In a Rails view, I'm trying to show a <select>
drop-down list for a number of different string fields with restricted values.
I've been trying to do this with a partial (below), but the current value is not being selected in the <select>
list.
- Is it possible to do this in a partial? If so, how?
- Is there a better approach to take?
edit.html.erb:
<% form_for(@my_class) do |f| %>
<%= render :partial => "select", :locals => { :attribute_name => :blah, :f => f } %>
<% end %>
_select.html.erb:
<p>
...
<%= f.label attribute_name %><br />
<%= f.select attribute_name, [:option_a,:option_b,:option_c], { :selected => attribute_name } %>
...
</p>