I am getting this error when trying to assign a Cart instance to a
parent.cart has_one assoc.
ActiveRecord::AssociationTypeMismatch in
CustomerOrdersController#create
Cart(#2188120600) expected, got Cart(#2198420140)
I can get it to work in the console but not in my app... I imagine I
am doing something screwy in the app, but, I'm confused by the
mismatch error as it says the two class instances are both of the same
class.
Thanks for the feedback. Both Carts are definitely the same Class (no
modules are at play). Everything works perfectly in the console. It
blows up when the app runs as Dev.
After I reboot the local server the first time the request is passed I
do NOT have the mismatch error. All subsequent calls blow up however.
Hard to tell without seeing code, but it sounds distinctly like you've
got the classic "putting ActiveRecord objects into the session"
problem. In development mode, this breaks in exactly this sort of
bizarre way because the classes are reloaded between requests.
...Or just reloaded classes in development. You can verify if this is, in fact, the problem by changing the:
config.cache_classes = false
to
config.cache_classes = true
and possibly
config.action_controller.perform_caching = true # usually false in development