If I have a RoR person.rb model as follows:
class Person < ActiveRecord::Base attr_accessible :first_name, :last_name validates :first_name, presence: true validates :last_name, presence: true end
I can't seem to do anything:
@full_name = @first_name + " " + @last_name
or
def full_name @first_name + " " + @last_name end
As far as I understand, both of them should work with the usual class of rubies.
I read a little, and it seems to be the way to go:
def full_name self.first_name + " " + self.last_name end
I can do this work, but I really would like to understand why I cannot in any way refer to instance variables (and not create new ones).
Does ActiveRecord :: Base use something extremely funny for instance variables? Does it limit the model (the Person class in this case) is nothing but a wrapper around what is in the database?
I can't determine attr_accessor either ... but I can set first_name and last_name just fine (not only through bulk assignment, but also p = Person.new; p.first_name = foo)
If someone can shed light on this, that would be very grateful.
Thank you very much,
source share