From 57a5ae566016ad47cb71d96356f058db096ca8d5 Mon Sep 17 00:00:00 2001 From: Ari Timonen Date: Mon, 26 Aug 2019 23:40:07 +0300 Subject: [PATCH] Add ability to add players to teams for admins WIP! --- app/models/teamer.rb | 12 ++++++++++++ app/views/teams/edit.html.erb | 27 +++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/app/models/teamer.rb b/app/models/teamer.rb index 54361ca..9e5a560 100644 --- a/app/models/teamer.rb +++ b/app/models/teamer.rb @@ -21,6 +21,7 @@ class Teamer < ActiveRecord::Base RANK_LEADER = 2 attr_protected :id, :created_at, :updated_at, :version + attr_accessor :username validates_length_of :comment, :in => 0..15, :allow_blank => true validates_uniqueness_of :user_id, :scope => [:team_id, :rank] @@ -28,6 +29,7 @@ class Teamer < ActiveRecord::Base #validate_on_create:validate_team #validate_on_create:validate_contests validate :validate_team + validate :validate_username scope :basic, :include => :user, @@ -77,6 +79,16 @@ class Teamer < ActiveRecord::Base end end + def validate_username + if username + if u = User.first(:conditions => {:username => username}) + self.user = u + else + errors.add(:username, t(:gatherer_wrong_username)) + end + end + end + def validate_contests # TODO end diff --git a/app/views/teams/edit.html.erb b/app/views/teams/edit.html.erb index d93f92c..e1fea6c 100644 --- a/app/views/teams/edit.html.erb +++ b/app/views/teams/edit.html.erb @@ -84,6 +84,19 @@ <%= f.submit "Update" %> <% end %> + + <%= form_for @team.teamers.build, html: { class: 'square' } do |f| %> + <%= f.hidden_field :team_id %> + +
+ <%= f.label :username, "Add user:" %> + <%= f.text_field :username %> +
+ +
+ <%= f.submit "Add" %> +
+ <% end %>
@@ -94,6 +107,20 @@
<%= f.collection_select :contest_id, Contest.active, :id, :name %>
+ <%= form_for @team.contesters.build, html: { class: 'square' } do |f| %> + <%= f.hidden_field :team_id %> + +
+ <%= f.collection_select :contest_id, Contest.active, :id, :name %> +
+ +
+ <%= f.submit "Join" %> +
+ <% end %> +

+
+
<%= f.submit "Join" %>