Reputation: 366
So I've got a form for a Group model
has_many :people, through: :group_persons
has_many :group_persons
On the form, I want to have two select boxes where the user can select from the same list of People:
<%= f.label "Sub Group A" %>
<%= f.select :group_person_ids, Person.all %>
<%= f.label "Sub Group B" %>
<%= f.select :group_person_ids, Person.all %>
The selected people from each select box will BOTH get written into the group_persons table eventually, but I want them sent back to the controller as separate lists for handling first, so I want my parameters to look something like this:
"group"=>{ "group_persons_subgroup_a"=>"1", "group_persons_subgroup_b"=>"3", "commit"=>"Save"}
What do I need to do in the view to achieve this?
Upvotes: 0
Views: 33
Reputation: 20253
Check out select_tag. It allows you to specify distinct names for your selects and, thereby, your submitted values.
It might look something like :
select_tag "group_persons_subgroup_a", options_from_collection_for_select(Person.all, "id", "name")
That may not be precisely correct, so you'll have to fiddle with it.
BTW, good on you for using Person
instead of User
. We are more than our role in relation to our computer!
Upvotes: 2