Pat Mac
2005-Apr-04 23:22 UTC
Validation problem with active record: AssociationTypeMismatch
[Rails] 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
Possibly Parallel Threads
- Validation problems: ActiveRecord::AssociationTypeMismatch
- Forms: handle foreign keys (AssociationTypeMismatch)
- Problem with belongs_to associations validating associated class: bug in rails in development mode?
- habtm and options_from_collection_for_select [1.0.0]
- select helper question