Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Browse files

Warning about using select on associations

  • Loading branch information...
1 parent 904b3d8 commit 074b1138b69d6b84cdde8c926b4807282b1be338 @fcheung fcheung committed
Showing with 8 additions and 0 deletions.
  1. +8 −0 railties/doc/guides/source/form_helpers.txt
8 railties/doc/guides/source/form_helpers.txt
@@ -403,6 +403,14 @@ As before, if you were to use `select` helper on a form builder scoped to `@pers
<%=, ...) %>
+If you are using `select` (or similar helpers such as `collection_select`, `select_tag`) to set a `belongs_to` association you must pass the name of the foreign key (in the example above `city_id`) and not the name of association itself. Active Record will raise an error along the lines of
+ActiveRecord::AssociationTypeMismatch: City(#17815740) expected, got Fixnum(#1138750)
+when you pass the params hash to `` or `update_attributes` if you specify `city` instead of `city_id`. Another way of looking at this is that form helpers only edit attributes.
Option tags from a collection of arbitrary objects

0 comments on commit 074b113

Please sign in to comment.
Something went wrong with that request. Please try again.