简体   繁体   中英

Simple_form: How to set f.input with with boolean values?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM