从具有简单形式的文本输入数组中进行选择

时间:2013-09-21 02:08:07

标签: ruby-on-rails twitter-bootstrap 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

1 个答案:

答案 0 :(得分:0)

试试这个:

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'%>
相关问题