Google Groups

Problem with overriding rails accessor methods


Paul Corcoran Aug 20, 2006 2:47 PM
Posted in group: Ruby on Rails: Talk
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