I want to have popup menus and check boxes in my forms to let users
select associated objects. In the form I’m working on, the object
“belongs_to” another type of object which is selected from a popup menu.
The id of the chosen object(s) for association is passed back in the
parameter hash, but when rails creates a new object from this parameter
hash, I get a AssociationTypeMismatch. This error seems to be
complaining that rails expected an actual association object but it
instead got a string with the object’s id. I’m not sure why rails would
be expecting the actual associated object to be in the param hash
arriving from the form, but I’m still relatively new and am probably
doing something wrong.
Is there a way to instruct rails to expect an id in the param hash of a
form rather than the actual associated object? I think I could make
this work by overriding the ActiveRecord::Base update_attributes or
attributes= methods, but I’m betting this problem has been worked out
already since this is such a generic issue.