2016-07-16 62 views
1

我有当这些单选按钮两种形式之间复制的一种形式:simple_form收集单选按钮

= f.collection_radio_buttons :type, [['cardio', 'Cardio'], ['weights', 'Weights']], :first, :last, :item_wrapper_class => 'radio-inline' 

有没有办法添加一个类的单选按钮,所以这些可以通过jQuery很容易区分和你将如何使用haml来做到这一点,就像我追加ID一样,数据库上的值是否被更改?

+0

我从来没有使用'简单形式',但我会认为它为你做。在加载页面时查看呈现的html并查看它输出的内容。当然,你可以不使用'simple-form'并使用[普通的radio_button](http://apidock.com/rails/ActionView/Helpers/FormHelper/radio_button)。 –

回答

0

的集合单选按钮,如:

form_for @user do |f| 
    f.collection_radio_buttons :options, [[true, 'Yes'] ,[false, 'No']], :first, :last 
end 

结果

<input id="user_options_true" name="user[options]" type="radio" value="true" /> 
<label class="collection_radio_buttons" for="user_options_true">Yes</label> 
<input id="user_options_false" name="user[options]" type="radio" value="false" /> 
<label class="collection_radio_buttons" for="user_options_false">No</label> 

https://github.com/plataformatec/simple_form#collection-radio-buttons

所以,你应该尽量覆盖CSS类的collection_radio_buttons“,并在生成的 'ID'输入。