开发者

What does :layout tag in respond_with do in Rails 3?

What does the code below's :layout do?

respond_with( @comment, :layout => !request.xhr? )

The code above is handling rendering of the differe开发者_如何学编程nt MIME type based on request data type (If my understanding is correct). What is the :layout tag doing?


From the documentation for ActionController::Responder

respond_with also allow you to pass options that are forwarded to the underlying render call. Those options are only applied success scenarios. For instance, you can do the following in the create method above:

So what the :layout => !request.xhr? it will pass this option down to the rendering. So if you had an HTML resource called as a regular request, it would use the standard layout, but an HTML request made as an XmlHttpRequest would not use a layout


You do not need to use the format way. This perfectly works too:

respond_to :html; :json
respond_with(@product, :layout => "landingpage")
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜