格式为 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.

相关文章