In my db, I've a boolean field: is_in_city
.
In view, I try to set check_box_tag
as:
= check_box_tag c.is_in_city
But it is never checked even if the db value is true. What is wrong?
I need to do such chekbox
, which is no/is checked according to db boolean field value stored in the database. How can I do this? Also how can I set one more my property to checkbox?
The proper use of the check_box_tag
method is like this:
= check_box_tag :name, value, checked
Where value
can be anything, checked
(should be) a boolean.
In your case:
= check_box_tag :is_in_city, 1, c.is_in_city
Documentation here: http://api.rubyonrails.org/classes/ActionView/Helpers/FormTagHelper.html#method-i-check_box_tag
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With