簡體   English   中英

下拉列表中的軌道

[英]Drop down list in rails

    <% 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 %>

如何將此下拉列表更改為不帶單選按鈕的常規下拉列表?

您可以這樣進行:

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

然后使用選擇標簽幫助器。 如果在form_for model do |f| 做標簽

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

如果帶有form_tag標記,請執行

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

查看EdgeGuides以獲得更多信息以及RoR API。

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM