开发者

determining format of response in rails

开发者 https://www.devze.com 2023-02-06 00:33 出处:网络
When I \'GET /pages.js\' rails routes the request like this: { :controller => \'pages\', :action =>开发者_开发问答 \'index\', :format => \'js\' }

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消