当格式为JS(需要烘干)时渲染无布局 [英] Render without layout when format is JS (needs drying)
本文介绍了当格式为JS(需要烘干)时渲染无布局的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的控制器中有这个:
respond_to do |format|
format.html
format.js { render :layout => false }
end
当请求是Ajax时,哪些输出没有布局。我在许多动作和控制器中复制它。我该如何干这个?
Which outputs without layout when the request is Ajax. I'm replicating this in many actions and controllers. How do I DRY this?
推荐答案
我在我的应用程序控制器中使用它:
I use this in my application controller:
class ApplicationController < ActionController::Base
layout proc{|c| c.request.xhr? ? false : "application" }
end
其中包括.js,.json等。对我来说。
Which covers .js, .json, etc. for me.
这篇关于当格式为JS(需要烘干)时渲染无布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文