开发者

Can't save collection_select to object

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, { :promp开发者_StackOverflow社区t => 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!


Shouldn't it be?

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜