determining format of response in rails
When I 'GET /pages.js' rails routes the request like this:
{ :controller => 'pages', :action =>开发者_开发问答 'index', :format => 'js' }
I'm looking for the code that determines the format to return to the client which I assume is in action_dispatch but I'm having a difficult time locating it.
consider
def index
@posts = Post.all
respond_to do |format|
format.html # index.html.erb
format.js { render :json => @posts}
end
end
There's another extension to the above which lets you render a template to customise the json response; same goes for xml. Hope this helps.
Cheers, Mike.
精彩评论