On 8/20/06, Paul Corcoran
<prcorcoran-Wuw85uim5zDR7s880joybQ@public.gmane.org>
wrote:>
>
> Hello all,
>
> I just encountered something that is not what I would expect. I
> overrode an accessor method in my model class and within this method I
> did a "super" call which failed. Of couse my real method would be
doing
> more but here is the basic code that shows the problem:
>
> class Word < ActiveRecord::Base
> belongs_to :verse
> belongs_to :grammar_tense_code
>
> def grammar_tense_code
> obj = super
> end
> end
>
> In my view I call: <td><%= word.grammar_tense_code.descr
%></td>
>
> The error message I get is: "super: no superclass method
> `grammar_tense_code''".
>
> I realize there is no real ''grammar_tense_code'' method
and that rails
> handles this for me. BUT, I would have expected the message to be
> passed up the chain and handled by Rails active record code which would
> read the database. This is typical oo behavior. Does anybody know what
> is happening here and how to work around it?
>
> (Incidentally, if I remove this method everything works fine. Rails
> retrieves the object from the database and gives me it''s
"descr"
> attribute.)
>
> Thanks in advance,
> Paul
Active Record uses method_missing to dynamically read and write attributes.
Use read_attribute(''grammar_tense_code'') within your method
rather than
super.
jeremy
--~--~---------~--~----~------------~-------~--~----~
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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk
-~----------~----~----~----~------~----~------~--~---