简体   繁体   English

如何从 Rails 页面上的特定 Ruby 中删除应用程序布局?

[英]How to remove application layout from a particualar Ruby on Rails page?

How can I remove the layout application.html.erb from rendering on a particular page.如何从特定页面上的呈现中删除布局 application.html.erb。 It is now visible on all pages in my application.它现在在我的应用程序的所有页面上都可见。

You can override default rendering at the controller level.您可以在 controller 级别覆盖默认渲染。

class Admin::HomeController < Admin::BaseController
  layout "admin"

You can also override rendering of layouts at a controller action level:您还可以在 controller 操作级别覆盖布局的呈现:

def show
  render :layout => "layout_for_show_only"
end

And, if you are really desperate, you can override layouts in the view:而且,如果你真的很绝望,你可以覆盖视图中的布局:

<%= render "print_view", :layout => "print" %>

See the excellent rails guide on the subject: layouts and rendering in Rails请参阅有关该主题的优秀 Rails 指南: Rails 中的布局和渲染

ian.伊恩

You can simply add to the controller:您可以简单地添加到 controller:

layout false, only: [:show, :edit]

which means, that application layout won't be rendered for the show and edit pages这意味着,将不会为显示和编辑页面呈现该应用程序布局

Here is an answer.这是一个答案。

You can set: format.js {render:layout=>false}你可以设置:format.js {render:layout=>false}

jQuery + Ajax + Haml. jQuery + Ajax + 哈姆尔。 js.erb files not firing js.erb 文件未触发

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从 Ruby on Rails 应用程序中删除 gem? - How to remove gem from Ruby on Rails application? Ruby on Rails:在没有应用程序布局的情况下渲染页面 - Ruby on Rails: Rendering a Page without the Application Layout Ruby/Rails - 从我的应用程序中删除 ActiveAdmin - Ruby/Rails - Remove ActiveAdmin from my application 根据页面类型在应用程序布局中加载不同的CSS(Ruby on Rails) - Load different CSS in application layout based on page type (Ruby on Rails) 如何在Ruby on Rails上将布局链接到视图页面 - how do I link a layout to a view page on Ruby on Rails Ruby on Rails - 如何在没有应用程序布局的情况下呈现动作? - Ruby on Rails - How do I render an action without the application layout? ruby on rails如何渲染没有布局和其他头部字段的页面 - ruby on rails how to render a page without layout and other head field Ruby on Rails:应用程序布局出现在弹出窗口 - ruby on rails: application layout appearing in popup 为什么在我的博客应用程序上显示此内容? 〜Ruby on Rails〜我不怎么删除网页结尾处的奇怪内容 - Why it display me this on my blog application? ~Ruby on Rails~I don't how to remove a strange thing at the end of the web page 如何在Ruby on Rails中将视图从“职位”应用程序渲染到我的主页上? - How to render a view from my “posts” application onto my Home page in Ruby on Rails?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM