Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

rails3 - check_box_tag - how to make a Conditional Disabled

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

like image 786
AnApprentice Avatar asked Jan 18 '11 07:01

AnApprentice


2 Answers

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.

like image 80
Chowlett Avatar answered Nov 15 '22 00:11

Chowlett


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

<%= check_box_tag 'XXXXXXX', 'true', true, :disabled =>  @setting.archived %>
like image 33
Bryan Morrow Avatar answered Nov 14 '22 23:11

Bryan Morrow