2010-11-02 51 views
0
<% form.inputs do %> 
     <% @account.account_preference.editorial_attributes.each do |key, value| %> 
     <%= account_pref.input "editorial_#{key}".to_sym, :as => :radio, :collection => options_for(Editorial, key.to_sym), :wrapper_html => { :class => "compact" }, :label => key.titleize %> 
     <% end %> 
    <% end %> 

如何将此下拉列表更改为常规下拉列表而无需单选按钮?在栏杆中的下拉列表

回答

0

你可以这样来做:

account_pref_options = [] 
@account.account_preference.editorial_attributes.each do |k,v| 
    account_pref_options << [k.titleize, "editorial_#{key}"] 
end 

然后用SELECT标签帮手。如果form_for model do |f|标签内,做

<%= f.select :field_name, account_pref_options_options %> 

如果witin一个form_tag标签,以获取更多信息以及RoR的API做

<%= select_tag(:field_name, options_for_select(account_pref_options)) %> 

退房的EdgeGuides。

http://edgeguides.rubyonrails.org/form_helpers.html#the-select-and-option-tags