If a type of a column is boolean, you must not use “as_boolean” in input field. 【Ruby on Rails】
1 min readApr 18, 2021
Sometimes, we see a column which is a “flag”. For example, “status”, “deleted”, and “is_changed”. If their types are boolean, you shouldn’t use as_ boolean input option for the columns.
Because the value is “0” or “1”, which means the type is number. We have to change the numbers into booleans somewhere. It leads to a bug. Actually, the code caused a bug of Stripe(https://stripe.com/en-jp) in our project.
Instead of that, we have to write codes like below.
<%= f.input :published, checked_value: :true, unchecked_value: :false %>
If you want to use “as_boolean”, the type of the column should be number.