On Fri, Oct 17, 2008 at 12:32 AM, zubin <[EMAIL PROTECTED]> wrote:
>
> Hey guys,
>
> I'm using method_missing in one of my AR models, like this:
>
> class Item < ActiveRecord::Base
> # Helper for finding properties, eg item.size
> def method_missing(symbol, *args)
> super
> rescue NoMethodError => e
> eval("properties.find_#{symbol}") || raise(NoMethodError, e)
> end
> end
Just a minor stylistic nitpick, you should really avoid rescuing and
re-raising that exception like that, check ahead of time.
> Appears that when NoMethodError is raised by association_proxy, it can
> longer be rescued. This happens when rendering a view (trace below).
>
> Odd thing is that it works from script/console:
>>> Cart.first.items.first.size
> => #<Property id: 2, property_type_id: 1, position: 4, code: "01",
> g1_code: "01", name: "small", webname: "small", description: nil>
Can you reproduce this breakage in a stand-alone application or as a
patch the the rails unit tests? It's pretty hard for me to tell
what's going on based on this trace and this email.
Did you remembert to override respond_to? when you overrode
method_missing? If those two don't align there's no guarantee you'll
get the behaviour you expect.
--
Cheers
Koz
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Core" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-core?hl=en
-~----------~----~----~----~------~----~------~--~---