I have something like this as a select_tag :
<p><%= setting_select :ui_theme, My::Themes.themes.collect {|t| [t.name, t.id]}, :blank => :label_default, :label => :label_theme %></p>
Rite now it is collecting all the values and displaying but I want to collect only a specific value and make it default. This value has name = “Test”.
Thus it should look like this and it should be default:
<option selected="selected" value="Test">Test</option>
Note : Here setting_select is a helper which is defined like this:
def setting_select(setting, choices, options={})
if blank_text = options.delete(:blank)
choices = [[blank_text.is_a?(Symbol) ? l(blank_text) : blank_text, '']] + choices
end
setting_label(setting, options).html_safe +
select_tag("settings[#{setting}]",
options_for_select(choices, Setting.send(setting).to_s),
options).html_safe
end
options_for_selectallows you to pre-select an option by passing its value. Example:output:
More information about select tag and options_for_select.