Right now I have the following in my as_json method in a model:
#values we will pass to Json
def as_json(options={})
super(:only => [:name, :last_name, :age])
end
I have a method that does some logic and returns a value:
def self.full_name
self.name + self.last_name
end
How can I return the “options” result in the as_json along with the fields that I already have? I have tried this:
#values we will pass to Json
def as_json(options={})
super(:only => [:name, :full_name => self.full_name, :last_name, :age])
end
With no luck.
Shadwell’s answer is completely correct. However, I think that you could just use the
:methodskey like this: