Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

collection_select method gives error in Rails 3.1.1

I have a Model called Category and other Model Product. They have has_many and belongs_to relation. But code in my view

    <p><%= f.collection_select(:product, :category_id, Category.all, :id, :name)%>

is giving me

 undefined method `merge' for :name:Symbol

Any clue what is wrong with it?

like image 510
Bhushan Lodha Avatar asked Nov 16 '11 05:11

Bhushan Lodha


1 Answers

Chances are you have something like this:

<%= form_for @product do |f| %>

Because f is already tied to product, you don't need to include it as your first argument, so it should just be:

<%= f.collection_select :category_id, Category.all, :id, :name %>

Or, you could not use f.:

<%= collection_select :product, :category_id, Category.all, :id, :name %>
like image 145
Dylan Markow Avatar answered Oct 11 '22 23:10

Dylan Markow