This project is archived and is in readonly mode.

AssociationProxy#method_missing masks method_missing in models
Reported by Steven Soroka | March 30th, 2009 @ 10:38 PM | in 2.x
This was discussed in #1515, 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.
Comments and changes to this ticket
- 
            
         
- 
            
         Steven Soroka March 30th, 2009 @ 10:44 PM- Tag set to 3.0, active_record, association_proxy, method_missing, nomethoderror
 
- 
            
         Steven Soroka March 31st, 2009 @ 09:47 PM- 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] 
- 
            
         Birkir A. Barkarson May 13th, 2009 @ 04:03 AMThis patch seems to do it for me. Wouldn't removing the rescue bit help with the other problem? 
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>
People watching this ticket
Attachments
Referenced by
- 
         1515 
          NoMethodError in AssociationProxy#method_missing isn't helpful
        I have a better solution, which I've provided with a patc... 1515 
          NoMethodError in AssociationProxy#method_missing isn't helpful
        I have a better solution, which I've provided with a patc...
- 
         3527 
          undefined method `destroyed?' for ActiveRecord::Associations::BelongsToAssociation
        This looks as if it is very closely related to #1515 and
... 3527 
          undefined method `destroyed?' for ActiveRecord::Associations::BelongsToAssociation
        This looks as if it is very closely related to #1515 and
...
 Birkir A. Barkarson
      Birkir A. Barkarson