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.

Thoughts?


--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Search Discussions

  • Peter Vandenabeele at Sep 21, 2011 at 7:56 am

    On Wed, Sep 21, 2011 at 12:29 AM, elliottg wrote:

    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.

    Thoughts?
    Not sure, but a possibility is that one of the 2 Cart classes is
    really MyModule::Cart and the other ::Cart . You may check if
    you have defined class Cart in a module. Maybe you then
    need to use the fully qualified name ::Cart or MyModule::Cart.

    HTH,

    Peter

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
  • Elliottg at Sep 21, 2011 at 1:52 pm
    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.

    Thoughts?

    Thanks, EG

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
  • Matt Jones at Sep 21, 2011 at 2:07 pm

    On Sep 21, 9:52 am, elliottg wrote:
    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.

    --Matt Jones

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
  • Rob Biedenharn at Sep 21, 2011 at 2:23 pm

    On Sep 21, 2011, at 10:07 AM, Matt Jones wrote:
    On Sep 21, 9:52 am, elliottg wrote:
    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.

    --Matt Jones
    ...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

    -Rob

    Rob Biedenharn
    Rob@AgileConsultingLLC.com http://AgileConsultingLLC.com/
    rab@GaslightSoftware.com http://GaslightSoftware.com/

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
  • Elliottg at Sep 21, 2011 at 8:15 pm
    Thanks for the inout guys. Sessions are at play, but I'm only storing
    the Cart's id. I'll try the config.cache_classes setting and get back
    to you.

    EG

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
  • Elliottg at Sep 21, 2011 at 8:36 pm
    config.cache_classes = true worked. But that opens up a whole new
    issue right? IE reboot server after each model edit?!

    Thoughts?
    PS thanks for the help so far.

    EG
    On Sep 21, 4:14 pm, elliottg wrote:
    Thanks for the inout guys. Sessions are at play, but I'm only storing
    the Cart's id. I'll try the config.cache_classes setting and get back
    to you.

    EG
    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouprubyonrails-talk @
categoriesrubyonrails
postedSep 20, '11 at 10:30p
activeSep 21, '11 at 8:36p
posts7
users4
websiterubyonrails.org
irc#RubyOnRails

People

Translate

site design / logo © 2021 Grokbase