Search code examples
ruby-on-railssimple-form

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"]

Solution

  • 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!