Hi everyone, I''m starting on my first rails project and I have a problem that I''m sure has a simple solution. I have two models, an address model and a state model. The address belongs_to :state, foreign_key=>"state" and validate_associated :state I have new & edit controllers for address which contain a drop down list for the state choice. My list was created with options_from_collection_for_select @states, "id", "name", @address.state When I go to the new or edit page, everything looks good. However, when I submit my new record (or edit an existing one) I get an ActiveRecord::AssociationTypeMismatch Expected type State but found string instead. I can see that the proper ID is being returned, it''s just being read by ruby as a string and I''m not sure how to cast it. I tried using the various before_validation functions, but they never seem to be called (I was explicitly throwing exceptions inside them to make sure). I''m totally stuck. --Pat
MCNAMAP-H4g33TCZ9qulQ9BUahrlcQ@public.gmane.org
2005-Apr-05 12:47 UTC
Validation problems: ActiveRecord::AssociationTypeMismatch
Hi everyone, I''m starting on my first rails project and I have a problem that I''m sure has a simple solution. I have two models, an address model and a state model. The address belongs_to :state, foreign_key=>"state" and validate_associated :state I have new & edit controllers for address which contain a drop down list for the state choice. My list was created with options_from_collection_for_select @states, "id", "name", @address.state When I go to the new or edit page, everything looks good. However, when I submit my new record (or edit an existing one) I get an ActiveRecord::AssociationTypeMismatch Expected type State but found string instead. I can see that the proper ID is being returned, it''s just being read by ruby as a string and I''m not sure how to cast it. I tried using the various before_validation functions, but they never seem to be called (I was explicitly throwing exceptions inside them to make sure). I''m totally stuck. --Pat
Seemingly Similar Threads
- Validation problem with active record: AssociationTypeMismatch
- Forms: handle foreign keys (AssociationTypeMismatch)
- habtm and options_from_collection_for_select [1.0.0]
- ActiveRecord::AssociationTypeMismatch (User(#54754560) expected, got User(#54510280))
- Paperclip attachment to AWS - ActiveRecord::AssociationTypeMismatch Going Nuts!