I am running into a problem with to_json not rendering my virtual attributes
class Location < ActiveRecord::Base
belongs_to :event
before_create :generate_oid
validates_associated :event
attr_accessor :event_oid
def event_oid
@event_oid = event.oid
end
end
event_oid is not part of the array returned by:
Location.first.attributes
This is particularly a problem for me when using to_json that automatically serializes record attributes to jason. to_json omits my virtual attribute.
How can you make a virtual attribute treated as an actual instance attribute?
Edit:
to_json is just an example of a method where having my virtual attribute treated as an actual attribute would be nice.