rails3 - check_box_tag - how to make a Conditional Disabled

风格不统一 提交于 2019-12-23 09:36:56

问题


Given the following Rails 3 check_box_tag

<%= 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


回答1:


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.




回答2:


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

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


来源:https://stackoverflow.com/questions/4721365/rails3-check-box-tag-how-to-make-a-conditional-disabled

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!