I have a controller named CourseRequests which will be accepting an ajax request for the "new" method.
Since it will be responding with json, should I use /course_requests/new.json?
I don't want to make a template for such a silly json response, how would I do that?
What does respond_to do? (I have seen it block style and I understand that, but what about non-block style)
Yes, your JS would be doing something along the lines of:
$.getJSON("/course_requests/new.json",...);
You don't have to, you just need to have a respond_to block with JSON handled there.
respond_to do |format|
format.json { render :json => "test" }
end
Blockless syntax, I think you mean this: http://davidwparker.com/2010/03/09/api-in-rails-respond-to-and-respond-with/ . Basically, you specify what mime types your controller responds to and then you can use the cooler responds_with method.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With