2010-11-02 106 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