我有类似的东西作为select_tag:
<p><%= setting_select :ui_theme, My::Themes.themes.collect {|t| [t.name, t.id]}, :blank => :label_default, :label => :label_theme %></p>
Rite现在收集所有值并显示但我想只收集一个特定的值并将其设为默认值。该值具有name =“Test”。
因此它应该是这样的,它应该是默认的:
<option selected="selected" value="Test">Test</option>
注意:这里的setting_select是一个帮助器,定义如下:
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
答案 0 :(得分:0)
options_for_select
允许您通过传递其值来预先选择一个选项。示例:
<%= options_for_select([['Lisbon', 1], ['Madrid', 2], ...], 2) %>
输出:
<option value="1">Lisbon</option>
<option value="2" selected="selected">Madrid</option>