Anadi Misra
Anadi Misra

Reputation: 2103

rails simple_form prevent select adding a blank by default to collection

I'm rendering an array of strings using collections in simple-form gem, I've gone through this answer, but the solutions there did not work well.

here's the Tag

<%= f.input :training_modes, collection: get_training_modes, include_blank: false, input_html: { multiple: true } %>

But when I save through this select I get arrays like these

["", "Instructor Led Training", "Webex"]

Upvotes: 4

Views: 3479

Answers (1)

Rajdeep Singh
Rajdeep Singh

Reputation: 17834

You need to pass include_hidden: false option with the select to remove the hidden field

<%= f.input :training_modes, collection: get_training_modes, include_blank: false, include_hidden: false, input_html: { multiple: true } %>

Hope that helps!

Upvotes: 7

Related Questions