开发者

rails3 - check_box_tag - how to make a Conditional Disabled

开发者 https://www.devze.com 2023-02-05 01:26 出处:网络
Given the following Rails 3 check_box_tag开发者_如何学C <%= check_box_tag \'XXXXXXX\', \'true\', true, (@setting.archived == true, :disabled =>?true : false ) %>

Given the following Rails 3 check_box_tag

开发者_如何学C
<%= check_box_tag 'XXXXXXX', 'true', true, (@setting.archived == true, :disabled =>  ?  true : false ) %>

How do I make the disabled setting conditional on @setting.archived ?

Any ideas?

Thanks


You've nearly got something that'll work. Try:

<%= check_box_tag 'XXXXXXX', 'true', true, :disabled =>  (@setting.archived ?  true : false ) %>

remembering that (test ? a : b) is a single expression evaluating to a if test is true, and b if it's false.


To shorted Chowlett's answer, you can just do:

<%= check_box_tag 'XXXXXXX', 'true', true, :disabled =>  @setting.archived %>
0

精彩评论

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