5

I have models that look something like this:

class Team
  has_many :users, through: :team_members
end

class User
  has_many :teams, through: :team_members
end

class TeamMember
  belongs_to :team
  belongs_to :user
  # with a boolean attribute of :team_captain
end

I am able to select the team members using a Rails 4 collection of check boxes:

<%= form_for @team do |f| %>
  <%= f.text_field :name %>
  <%= f.collection_check_boxes :users, User.order(:name), :id, :name %>
<% end %>

However, I also need the ability to specify the team captain. I'm sure there's a way to handle this in Rails, but I'm not sure how to do it.

user2864740
  • 60,010
  • 15
  • 145
  • 220
Andrew
  • 227,796
  • 193
  • 515
  • 708

0 Answers0