简体   繁体   English

删除特定rails .html.erb文件中的标头呈现

[英]Removing header rendering in specific rails .html.erb file

I'm rendering a header universally across my application in layouts/application.html.erb. 我正在layouts / application.html.erb中的应用程序中普遍呈现标题。

I'd like to make the header not appear in a specific foo.html.erb file. 我想让标题不出现在特定的foo.html.erb文件中。

What's the syntax for un-rendering a universal layout? 解除通用布局的语法是什么?

EDIT: 编辑:

The controller for the layout is a devise controller, specifically Sessions Controller. 布局的控制器是设备控制器,特别是会话控制器。

in your controller you can set the layout to false (or another layout), if false then you need all of the html,head,body tags in your view file 在您的控制器中,您可以将布局设置为false(或其他布局),如果为false,则需要视图文件中的所有html,head,body标签

class BarController < ApplicationController
  def foo
    render :layout => false # render foo.html.erb with no layout
  end 
end

see section 2.2.11.2 from the rails guides: http://guides.rubyonrails.org/layouts_and_rendering.html 请参阅rails指南中的第2.2.11.2节: http ://guides.rubyonrails.org/layouts_and_rendering.html

EDIT: including devise layout overrides 编辑:包括设计布局覆盖

in config/initializers/devise.rb 在config / initializers / devise.rb中

Devise::SessionsController.layout "bar"
Devise::RegistrationsController.layout "foo"
Devise::ConfirmationsController.layout false # never tried this, guessing it would work
Devise::UnlocksController.layout "bar"
Devise::PasswordsController.layout "foo"

also see the wiki post - https://github.com/plataformatec/devise/wiki/How-To:-Create-custom-layouts has at least one other way 还可以看到wiki帖子 - https://github.com/plataformatec/devise/wiki/How-To:-Create-custom-layouts至少有一种方式

Let's say the controller and action that renders the template foo.html.erb is 'things#foo' and the path to this action is things_path. 假设呈现模板foo.html.erb的控制器和动作是'things#foo',这个动作的路径是things_path。 You can wrap the header in conditional tags as follows 您可以按如下方式将标头包装在条件标签中

<% unless request.path == things_path %>
<% end %>

. There are several ways to achieve this, but here is one. 有几种方法可以实现这一点,但这里有一个。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM