[英]Selecting from an array of Text Inputs with Simple Form
我在Rails 4中使用SimpleForm。我正在嘗試執行以下操作:
<%= f.input :options_for_example, collection: ["Option1", "Option2", "Option3","Option4"], :as => :radio_buttons, :item_wrapper_class => 'inline'%>
這種語法(類似)在Formtastic中有效,但是SimpleForm使用Bootstrap,所以我在使用SimpleForm。 我需要添加什么才能使它正常工作?
我的錯誤是未No input found for radio_buttons
。
嘗試這個:
將gem simple_form, '3.0.0rc'
添加到您的Gemfile中,進行運行bundle install
然后在視圖中使用以下代碼:
<%= f.input :options_for_example, collection: [ ['option1', 'Option 1' ], ['option2', 'Option 2'], ['option3', 'Option 3' ], ['option4', 'Option 4' ] ], as: :radio_buttons, item_wrapper_class: 'inline'%>
我在選擇以下性別(如果需要的話)時使用它:
<%= f.input :gender, label: 'What is your gender?', collection: [ ['M', 'Male' ], ['F', 'Female'] ], as: :radio_buttons, label_method: :last, value_method: :first, checked: @student.gender, item_wrapper_class: 'inline'%>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.