views:

16

answers:

1

I'm going crazy here.

I have:

class Course
   belongs_to :commune
end

and

class Commune
   has_many :courses
end

In the new view for Course I have a drop down where the user selects commune:

f.collection_select(:commune, get_commune_list, :id, :commune, { :prompt => true })

(The get_commune_list is a helper method that returns a list of Commune objects)

But when I try to save it I either get this error:

Commune(#2176182100) expected, got String(#2148246520)

or the Commune isn't saved on the Course object at all.

The parameters look like this:

{"course"=>{"price"=>"6000",
 "title"=>"Some title",
 "commune"=>"10",
 ...
}

I just can'† figure out why this won't work!

A: 

Shouldn't it be?

f.collection_select (:commune, :commune_id, get_commune_list, :id, :commune, { :prompt => true })
Amit
If I do that I get "undefined method `merge' for :commune:Symbol".If I use f.collection_select (:commune_id, get_commune_list, :id, :commune, { :prompt => true }), I get undefined method `commune_id' for #<Course:0x103657058>.
fiskeben
You many try doing something like f.select("commune_id", Commune.all.collect{ |c| [c.name, c.id]}, { :prompt => true})
Amit
Sigh... I forgot to add commune_id to the database. Another ten four hours well spent.Thanks for your answer. Since you let me on track I'll accept it.
fiskeben