Topic: Why can't I read my models attribute?

I have a model TcDatum whose backend table has a string attribute (field) named 'leave'.
(I just added 'leave' with a rails migration)

I added 'attr_accessible :leave' to the active record definition for TcDatum.

However, when I reference the attribute from within a fields_for loop as in:
<% if pf.object.leave=='P' %>
I get the error "undefined method 'leave' for #<TcDatum:xxxxxxx>"

If I add it explicitly to the model with the code
def leave
  'P'
end
then the fields_for code executes without error.

However, I want to read the field value from the model record, not create one with a def .. end.

What am I doing wrong that the model attribute 'leave' isn't being recognized in my code?

Thanks in advance for any help.  --Fred

Last edited by fredrated (2012-04-19 13:36:23)

Re: Why can't I read my models attribute?

My mistake, I feel like an idiot.
The migration I used to add 'leave' actually added the field to the parent table of TcDatum, not to TcDatum!  When I realized that and ran a migration to add 'leave' to TcDatum, Voila!  It works!