Fix gathers

This commit is contained in:
Ari Timonen 2020-04-03 09:48:32 +03:00
parent b24d2e987d
commit 2e6453dc6e
4 changed files with 18 additions and 11 deletions

View file

@ -46,6 +46,7 @@ class GathersController < ApplicationController
redirect_to @gather redirect_to @gather
end end
# FIXME: Use gatherers.update
def pick def pick
@gatherer = @gather.gatherers.find(params[:player]) @gatherer = @gather.gatherers.find(params[:player])
raise AccessError unless @gatherer.can_update? cuser, params raise AccessError unless @gatherer.can_update? cuser, params

View file

@ -30,7 +30,7 @@ class Gatherer < ActiveRecord::Base
#attr_protected :id #attr_protected :id
attr_accessor :confirm, :username attr_accessor :confirm, :username
cattr_accessor :skip_callbacks attr_accessor :skip_callbacks
scope :team, -> (team) { where(team: team) } scope :team, -> (team) { where(team: team) }
scope :of_user, -> (user) { where(user_id: user.id) } scope :of_user, -> (user) { where(user_id: user.id) }
@ -83,7 +83,7 @@ class Gatherer < ActiveRecord::Base
def validate_username def validate_username
if username if username
if u = User.where(username: username).exists? if (u = User.where(username: username).first)
self.user = u self.user = u
else else
errors.add(:username, t(:gatherer_wrong_username)) errors.add(:username, t(:gatherer_wrong_username))
@ -171,6 +171,6 @@ class Gatherer < ActiveRecord::Base
end end
def self.params(params, cuser) def self.params(params, cuser)
params.require(:gatherer).permit(:status, :user_id, :gather_id, :team, :votes) params.require(:gatherer).permit(:status, :username, :user_id, :gather_id, :team, :votes)
end end
end end

View file

@ -5,7 +5,7 @@
<%= if team.nil? then "Lobby" else team == 1 ? "Marines" : "Aliens" end %> <%= if team.nil? then "Lobby" else team == 1 ? "Marines" : "Aliens" end %>
</h4> </h4>
<%= form_tag "/gathers/pick/#{@gather.id}" do %> <%= form_tag pick_gather_path(@gather) do %>
<ul class="gatherers"> <ul class="gatherers">
<% @gather.gatherers.ordered.team(team).each do |gatherer| %> <% @gather.gatherers.ordered.team(team).each do |gatherer| %>
<li> <li>

View file

@ -41,7 +41,19 @@ Ensl::Application.routes.draw do
resources :shoutmsgs resources :shoutmsgs
resources :teamers resources :teamers
resources :teams resources :teams
resources :gathers resources :gathers do |g|
collection do
get :refresh
end
member do
post :pick
end
end
get 'gathers/latest/:game', to: "gathers#latest", via: :get
get 'gather', to: "gathers#latest", game: "ns2", via: :get
get 'gatherers/:id/status', to: "gatherers#status", via: :post
resources :gatherers resources :gatherers
resources :groups resources :groups
resources :groupers resources :groupers
@ -123,12 +135,6 @@ Ensl::Application.routes.draw do
get 'directories', to: "directories#show", id: 1 get 'directories', to: "directories#show", id: 1
get 'gathers/refresh'
get 'gathers/latest/:game', to: "gathers#latest", via: :get
get 'gather', to: "gathers#latest", game: "ns2", via: :get
get 'gatherers/:id/status', to: "gatherers#status", via: :post
get 'groups/addUser' get 'groups/addUser'
get 'groups/delUser' get 'groups/delUser'