aboutsummaryrefslogtreecommitdiffstats
path: root/railties/doc/guides/source
diff options
context:
space:
mode:
authorFrederick Cheung <frederick.cheung@gmail.com>2008-12-31 18:17:17 +0000
committerFrederick Cheung <frederick.cheung@gmail.com>2008-12-31 18:17:17 +0000
commit074b1138b69d6b84cdde8c926b4807282b1be338 (patch)
tree9d8f13578e5ba04962c984db5c505a7e1167b24e /railties/doc/guides/source
parent904b3d8fced8cd994c618628a9aebdca073a2d7d (diff)
downloadrails-074b1138b69d6b84cdde8c926b4807282b1be338.tar.gz
rails-074b1138b69d6b84cdde8c926b4807282b1be338.tar.bz2
rails-074b1138b69d6b84cdde8c926b4807282b1be338.zip
Warning about using select on associations
Diffstat (limited to 'railties/doc/guides/source')
-rw-r--r--railties/doc/guides/source/form_helpers.txt8
1 files changed, 8 insertions, 0 deletions
diff --git a/railties/doc/guides/source/form_helpers.txt b/railties/doc/guides/source/form_helpers.txt
index 7fb01bbf48..05f1b205db 100644
--- a/railties/doc/guides/source/form_helpers.txt
+++ b/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
<%= f.select(:city_id, ...) %>
----------------------------------------------------------------------------
+[WARNING]
+=============================
+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 `Person.new` 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
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~