In DB, I have a boolean
column, let's call it morning
.
In a view, this is how I display a select box menu:
= f.input :morning, label: false, required: true, collection: [["Yes", true], ["No", false]], input_html: { class: "..." }
However, when I send this form, nothing will be saved to DB.
If I try modify it, like this:
= f.input :morning, label: false, required: true, collection: ["Yes", "No"], input_html: { class: "..." }
Same thing happens.
What's the correct way of setting a select box with true/false
value?
Your issue is not with the values in collection, but with input type.
<%= f.input :morning, as: :select, collection: [['Yes',true], ['No',false]], required: true, include_blank: false %>
Something like this. Just pay attention to: as: :select