Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

AssociationProxy#method_missing masks method_missing in models

#2378

This was discussed in #1515 NoMethodError in AssociationProxy#method_missing isn't helpful, but was not addressed properly imho.

I've come up with a better solution, which goes ahead and sends the message on to the target model, and then catches any NoMethodErrors raised, and improves the error message; which was the original intent.

Reported by Steven Soroka · March 30th, 2009 @ 10:38 PM

State: invalid
Milestone: 2.x
Assigned to: nobody
Importance: none

Activity

  1. Steven Soroka
  2. Steven Soroka
    Steven Soroka
    • Tag set to 3.0, active_record, association_proxy, method_missing, nomethoderror

    March 30th, 2009 @ 10:44 PM

  3. Steven Soroka
    Steven Soroka
    • State changed from new to invalid

    gah. I found a problem with this. If the method is there and it calls something else that raises a NoMethodError, the method_missing here makes it seem as if it's @target's problem, when it's not.

    koz suggested instead just overriding responds_to? in your model if you're going to override method_missing, so that they match on which methods they respond to. Seems like a better approach.

    [state:invalid]

    March 31st, 2009 @ 09:47 PM

  4. Birkir A. Barkarson
    Birkir A. Barkarson

    This patch seems to do it for me. Wouldn't removing the rescue bit help with the other problem?

    May 13th, 2009 @ 04:03 AM