2014-03-01 36 views
0

如何從form_for helper獲取單選按鈕的值?Rails - 如果選中單選按鈕,則添加類

使用SLIM。

=form_for(@foo) do |f| 
    label[class="#{ f.type.value == 'type 1'? 'foo' : 'bar'}"] 
    | Type 1 
    = f.radio_button :type, 'Type 1' 
    label[class="#{ f.type.value == 'type 2'? 'foo' : 'bar'}"] 
    | Type 2 
    = f.radio_button :type, 'Type 2' 

犯規存在的值的方法。如何訪問表單助手的無線電方法的價值?

+0

你讀過了Rails的文檔? – emaillenin

+0

@emaillenin沒有提及訪問值[Rails](http://api.rubyonrails.org/classes/ActionView/Helpers/FormTagHelper.html#method-i-radio_button_tag) –

+0

任何人?..真的需要這個.. –

回答

0

按照this question,您可以使用實際@foo變量:

label[class="#{ @foo.type == 'type_2'? 'foo' : 'bar'}"] 
相關問題