How to customize the to_json method in rails3?
Posted
by
lashleigh
on Stack Overflow
See other posts from Stack Overflow
or by lashleigh
Published on 2011-01-16T02:46:25Z
Indexed on
2011/01/16
2:53 UTC
Read the original article
Hit count: 150
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
© Stack Overflow or respective owner