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" %>