开发者

ROR + HAML radio button issue for displaying readonly

开发者 https://www.devze.com 2023-02-17 03:34 出处:网络
HAML code to generate radioButton: = radio_button_tag \'options\', \"internal\", :checked => @option_value==2 ? true : nil,

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:

  1. RadioButton has to be readonly.

  2. 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消