Michael Schuerig
2005-May-01 20:32 UTC
Selecting target object for belongs_to association?
What''s the proper way to select the target object for a belongs_to association in a view? In my three weeks with Rails, so far, I''ve used collection_select "entry", "category_id", @categories, "id", "title" Now, this works -- almost. Validation error messages are not associated with the generated tag, because there are no errors on related_id. If any, there are errors on related. Looking at http://wiki.rubyonrails.com/rails/show/HowtoUseFormOptionHelpers http://dev.rubyonrails.org/ticket/1125 the right way would appear to be select "entry", "category", Category.find(:all).collect {|c| [ c.title, c.id ] } Which has the obvious drawback that it results in an error on submit: Category expected, got String Which is no surprise, really, as in the response entry["category"] is bound to the ID of the to be associated record, not the record itself. That leaves me stumped. What''s the way to handle this stuff? Michael -- Michael Schuerig Life is just as deadly mailto:michael-q5aiKMLteq4b1SvskN2V4Q@public.gmane.org As it looks http://www.schuerig.de/michael/ --Richard Thompson, Sibella