2016-07-16 66 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'輸入。