output. i’ve tried with attr_accessor but that didn’t work either.
foo.to_json(:methods => [:attr1, :attr2])
Maybe? (assuming that foo.attr1 returns one of your extra attributes)
hm… no luck with that either. when i try to print out the places object
in the console (logger.debug @place.to_yaml), “address” is missing.
From the top of my head (not hard tested now).
Now you refer to to_yaml, in previous mails, you refered to to_json.
Be careful, there is a fundamental difference between to_xml, to_json,
to_yaml on ActiveRecord …
One of them (I believe to_yaml) prints the “raw” database column values,
even if you overwrite that accessor function with a name. The other two
(to_json, to_xml IIRC) use the attribute accessors (from ActiveRecord I
presume), that can be overwritten by your own code.
So, I would expect to_yaml to never work in this scenario (where there
is
no database column). But to_json should be possible in this scenario
(I did some simple tests with ActiveModel and that seemed to work as
expected).
From then on, for that instance, you can call place.address, and it
will show up in place.to_json (since to_json is generated from
place.attributes, which now has a k/v for address in attributes).