New To Rails 3, ajax request with json response

10,298
  1. Yes, your JS would be doing something along the lines of:

    $.getJSON("/course_requests/new.json",...);
    
  2. 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
    
  3. 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.

Share:
10,298
Chris Muench
Author by

Chris Muench

Updated on June 15, 2022

Comments

  • Chris Muench
    Chris Muench almost 2 years

    I have a controller named CourseRequests which will be accepting an ajax request for the "new" method.

    1. Since it will be responding with json, should I use /course_requests/new.json?

    2. I don't want to make a template for such a silly json response, how would I do that?

    3. What does respond_to do? (I have seen it block style and I understand that, but what about non-block style)