<分区>
我的 Controller 里有这个:
respond_to do |format|
format.html
format.js { render :layout => false }
end
当请求是 Ajax 时,输出没有布局。我在许多 Action 和 Controller 中复制了这一点。我该如何烘干?
<分区>
我的 Controller 里有这个:
respond_to do |format|
format.html
format.js { render :layout => false }
end
当请求是 Ajax 时,输出没有布局。我在许多 Action 和 Controller 中复制了这一点。我该如何烘干?
最佳答案
我在我的应用程序 Controller 中使用它:
class ApplicationController < ActionController::Base
layout proc{|c| c.request.xhr? ? false : "application" }
end
这对我来说涵盖了 .js、.json 等。
关于javascript - 格式为 JS 时渲染无布局(需要干燥),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5729476/