I am following this really great tutorial. Now I would like to get the comments for a specific posting as JSON output.
Doing this for the posting is easy because it is just to call the .json. But how does it work with the comments?
I am following this really great tutorial. Now I would like to get the comments for a specific posting as JSON output.
Doing this for the posting is easy because it is just to call the .json. But how does it work with the comments?
So this is mostly sans-code, but the ideas should at least set you in the right direction.
To provide comments with their own route, first set up a route for comments in your routes.rb file, then create a show method in the comments controller (similar to the way you set it up for a posting). In the comments controller show method, just render the comment the same way you do for the posting.
It is a bit easier to just include comments along with the posting when requesting the json output. In the posts controller show method, use render :json => @posting.to_json(:include => :comment) (substitute @posting for the name of the Post object you find in the show method).