ruby-on-railssimple-formsimple-form-for

Empty array value being input with simple_form entries


I'm still new to rails and simple_form and have been trying to implement a multiple select option to give a user multiple roles.

Current input looks like this

<%= f.input :secondary_role, :collection => UseridRole::VALUES, :include_blank => false,:label => "Secondary Role(s):", :input_html => {  :class => " simple_form_bgcolour simple_form_position overide_selection_field_width", :size => 4, multiple: true } %>

So, this does work, but is including an empty value at the start of my array:

"secondary_role" : [
        "",
        "admin"
    ]

I have the same code above which works for my primary_role value which is a string, but my secondary_role can have multiple values so is stored as an array.

Where should I be looking to fix this issue?


Solution

  • It seems like Rails is adding a hidden field to the collection. Try adding include_hidden: false to your form input.