Just started learning Rails (3). I am tearing my hair out trying to find how to do something presumably utterly trivial: access the value of a model instance's field, from inside a method on that model.
In my case:
def formal_name
@title + " " + @forename + " " + @surname
end
All three @properties (which are all fields on the table in the database) return nil
. They shouldn't.
Incredibly, how to access fields isn't discussed at http://guides.rails.info/, and google turns up nothing.
BTW, I'm coming from Django where this stuff is obvious.
The @ syntax is used for instance variables that (for example) get populated in controllers and then used in views. Not what you're doing here.
You actually just need
def formal_name
title + " " + forename + " " + surname
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With