How to customize the to_json method in rails3?
- by lashleigh
I want to convert an array of Place objects to json, I've been doing it like this:
var places = <%= @places.to_json.html_safe %>;
The only problem is that every place in the @places array has an associated tag list that doesn't get included. I'm using the acts_as_taggable_on gem to handle tags, so to get the tag list for a place I need to say place.tag_list.
What do I have to do to get the tag_list included for each place in the javascript array? I think I'll need to write my own to_json method but I don't know how.
Thanks