If a type of a column is boolean, you must not use “as_boolean” in input field. 【Ruby on Rails】

Tomoharu Tsutsumi
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.

My LinkedIn account is below! Please contact me!

https://www.linkedin.com/in/tomoharu-tsutsumi-56051a126/

--

--

Tomoharu Tsutsumi
Tomoharu Tsutsumi

Written by Tomoharu Tsutsumi

5+ years Full Stack SWE (Ruby, Go, TypeScript, JavaScript) | Former Founding Engineer of AI Startup in Canada

No responses yet