I spent a good amount of time wrangling with as_json and overriding it
on
ActiveModel::Base like:
And to answer your question- methods is a good way of including
associations and whatever else you want to define that can be calculated
on
the model. But, please don’t use as_json unless you really need to.
Note: Mass assignment security (attr_accessible/attr_protected) is going
away in Rails 4. Also, there is a lot wrong with the implementation that
I’d developed that I’m trying to fix now.
Good luck.
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.