2010-11-02 5 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 %> 

Comment modifier cette liste déroulante à une liste déroulante régulière avec des boutons radio sur?Liste déroulante dans les rails

Répondre

0

Vous pouvez le faire de cette façon:

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

Ensuite, utilisez le select aide de la balise. Si dans une balise form_for model do |f|, faire

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

Si witin une balise form_tag, faire

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

Vérifiez les EdgeGuides pour plus d'informations, ainsi que l'API RoR.

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