从来没有呈现布局响应xhrs [英] Never render a layout in response to xhrs
本文介绍了从来没有呈现布局响应xhrs的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在大多数情况下,我不希望呈现一个布局时,请求来自AJAX。为此我一直在写渲染:布局=> !request.xhr?
经常在我的控制器动作。
Most of the time I don't want to render a layout when the request comes from AJAX. To this end I've been writing render :layout => !request.xhr?
frequently in my controller actions.
我怎样才能使这个的默认的?即,我希望能够写
How can I make this the default? I.e., I'd like to be able to write
def new
Post.find(params[:id])
end
和具备的功能是
def show
Post.find(params[:id])
render :layout => !request.xhr?
end
(我没事手动指定在其中我想用一个罕见的情况下的布局。)
(I'm fine manually specifying a layout in the rare cases in which I want to use one.)
推荐答案
这个怎么样?
class UsersController < ApplicationController
layout proc {|controller| controller.request.xhr? ? false: "application" }
end
这篇关于从来没有呈现布局响应xhrs的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文