Open hsamadi opened 12 years ago
Having surveyed some posts on Stack Overflow I noticed that most people follow Rails convention i.e. they use "to_json" method provided by ActiveRecord. By sticking to standards we can vaccinate our code against unseen problems :). So, I vote for ActiveRecord's to_json.
Second approach is the best choice.
@meqdadh But you were believing that the second approach may lead to more complex code! Something like this:
microblogs.to_json(:only => [:id, :title, :content], :methods => :posted_on, :include =>
{:comments => {:include => :user}})
@meqdadh was also thinking that the first approach generates less text. So it would be more efficient. But I think being concerned with this issue is a kind of premature optimization.
There are two approaches to create and send JSON response:
and create the JSON response manually
ActiveRecord
to create JSON responseWhich approaches do you think is better and why?