Ad

Inject Data Members To An Object

- 1 answer

This question is based on another question of mine(thankfully answered).

So if in a model I have this:

def self.find_extended
    person = Person.find(:first)
    complete_name = person.firstname + ', ' + person.lastname
    return person
end

How can I inject complete name in the person object so in my controller/view I can access it by person.complete_name?

Thank you for your time,
Silviu

Ad

Answer

I think the best way to do this is creation of complete_name attribute in your Person class:

def complete_name
  firstname + ', ' + lastname
end
Ad
source: stackoverflow.com
Ad