ROR + HAML radio button issue for displaying readonly
HAML code to generate radioButton:
= radio_button_tag 'options', "internal", :checked => @option_value==2 ? true : nil,
:disabled =>@option_value!=2 ? nil : true
HTML code for above HAML:
<input type开发者_开发技巧="radio" value="" name="options" id="options_external" checked="checked">
My requirements are:
RadioButton has to be readonly.
According to @option_value, radiobutton has to checked or unchecked. For example, above code has to be checked when @option_value=2.
= radio_button_tag 'options', "internal", @option_value == 2 ,
:disabled => @option_value == 2
The main differences:
1) You don't need to check the value of @option_value == 2 through a ternary operator, @option_value == 2 will return true or false, which is what you want.
2) :checked is not part of the optional hash in radio_button_tag, as seen here.
精彩评论