I’m trying to convert an ActiveRecord model to JSON in Rails, and while the to_json method generally works, the model’s virtual attributes are not included. Is there a way within Rails to list not just the attributes of a model, but also it’s attr_accessor and attr_reader attributes in order that all readable attributes are available when the model is converted to JSON?
Share
Before Rails 3, use the :method option:
In Rails 3, use :methods option