I don’t get the point how can I do that code with an select helper?
<select name="cube_name">
<% @cube_names.each do |cube| %>
<option value="<%= cube %>" <% if @cube_name == cube %> selected="selected"<% end %>><%= cube %></option>
<% end %>
</select>
I have a list (@cube_names) and want a HTML select box width all values of the list and the default value (param @cube_name) should be selected.
thanks.
The
select_taghelper will not auto-set theselectedattribute on an item you pass. It just builds the tag. Use something like:The first parameter is the id of the select tag, the second is a list of options (here built by mapping the cube names to strings, then joining the array into a single string).
You could alternatively use the
options_for_selectto build the string: