格式为 JS 时无布局渲染(需要晾干) [英] Render without layout when format is JS (needs drying)

查看:10
本文介绍了格式为 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆