I have a model question which has a column called category.
I have an array that lists all valid categories: Question.categories
<%= form_for(@question) do |f| %>
<%= f.select :category, options_for_select(Question.categories) %>
#...
<% end %>
Say I have a variable called @currentlySelectedCategory.
Now how do I tell rails to preselect the option in the dropdown menu that matches @currentlySelectedCategory?
<%= form_for(@question) do |f| %>
<%= f.select :category, options_for_select(Question.categories, @currentlySelectedCategory) %>
#...
<% end %>
But since you are using form_for
, I would have thought that rails would select the question category.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With