Ruby-on-Rails:如何将默认渲染选项 :layout 更改为“false”?
基本上就是这样。我希望 Ruby on Rails 3.1 应用程序中的大多数视图在没有布局的情况下呈现,因为它们将由 jQuery 分配给 div,但我不想转到每个控制器操作并设置 render :layout = >在respond_to 块中为 false。
是否可以将视图的默认渲染更改为 :layout =>假的?我该如何配置呢?
感谢您的帮助
编辑
我还可以通过以下方式解决它:
if request.xhr?
format.html { render :layout => false }
end
在每个respond_to块上执行。
That's basically it. I want most of the views in my Ruby on Rails 3.1 app to be rendered without layout, as they will be assigned to divs by jQuery, but I don't want to go to every controller action and set render :layout => false
in the respond_to block.
Is it possible to change the default rendering of views to :layout => false
? How would I go about configuring that?
Thank you for your help
EDIT
I could also solve it with a way to have something along the lines of:
if request.xhr?
format.html { render :layout => false }
end
be executed on every respond_to block.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您想要一些更高级的行为(例如在执行时确定布局),您还可以传递一个返回 nil 或有效布局名称的块:
If you want some more advanced behavior (such as determine de layaout in execution time) you also can pass a block that returns nil or a valid layout name: