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?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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
showmethod in the comments controller (similar to the way you set it up for a posting). In thecommentscontrollershowmethod, 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
postscontrollershowmethod, userender :json => @posting.to_json(:include => :comment)(substitute@postingfor the name of thePostobject you find in theshowmethod).