Reputation: 113
My select_tag is as follows.
<%= select_tag "group", options_from_collection_for_select(@groups, "id", "gname") %>
How do I obtain the selected value in my controller?
Upvotes: 0
Views: 120
Reputation: 23354
Use square brackets.
select_tag "group[]", options_for ....
Note the []. Rails will then store this as {"group" => [one option for each form]}.
If it's important to know which select provided which value, you can nest them, so
select_tag "group[bob]", ...
will provide {"group" => {"bob" => selected_option}}.
Basically, [] stores it in an array, and [key] stores it in a hash with that key.
Then in controller, you can use as:
params["group"]
, which should be an array of the various selects on the page.
Upvotes: 1
Reputation: 718
Try puts params
and check the your console to see values sent to the controller.
Upvotes: 0