Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

rails form select multiple gives empty first value

I have defined has_and_belongs_to_many associations between Meals and Recipes. In the Meals create form, I am using a select to populate the recipes.

<%= f.select :recipes, Recipe.all.collect { |x| [x.name, x.id]}, {}, :multiple => true %>

But the result set has a nil as the first value.

"recipes"=>["", "2", "7"]

How can I eliminate the empty/nil value?

like image 930
Michael Avatar asked Sep 16 '15 00:09

Michael


1 Answers

For me setting :include_hidden => false is what worked

<%= f.select :recipes, Recipe.all.collect { |x| [x.name, x.id]}, {:include_hidden => false}, :multiple => true %>
like image 53
Zuhaib Ali Avatar answered Oct 18 '22 07:10

Zuhaib Ali