除了某个动作之外,如何对所有内容进行局部渲染 [英] how to render partial on everything except a certain action

查看:46
本文介绍了除了某个动作之外,如何对所有内容进行局部渲染的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 _header.html.erb 部分,这是我放置导航栏的地方

在我的启动页面上,我不想显示导航栏.

这是application.html.erb的body

<%= 渲染布局/标题"%><div id="容器"><%=产率%>

除了特定控制器上的特定操作之外,我如何在每个操作上呈现它?

解决方案

用这个替换你的渲染:

<%= render 'layouts/header' 除非@disable_nav %>

然后您可以在您喜欢的任何控制器操作中简单地将 disable_nav 设置为 true:

def land_page@disable_nav = 真结尾

<小时>

作为 before_filter,我鼓励以上内容:

application_controller.rb

def disable_nav@disable_nav = 真结尾

my_controller

before_filter :disable_nav, only: [:landing_page]

I have a _header.html.erb partial which is where I put my navbar

on my launch page I don't want to display the navbar.

this is the body of application.html.erb

<body>
<%= render 'layouts/header' %>
<div id="container">
    <%= yield %>
</div>

</body>

How do I render it on every action except specific actions on specific controllers?

解决方案

Replace your render with this:

<%= render 'layouts/header' unless @disable_nav %>

Then you can simply set disable_nav to true in any controller action you like:

def landing_page
  @disable_nav = true
end


As a before_filter, which I'd encourage over the above:

application_controller.rb

def disable_nav
  @disable_nav = true
end

my_controller

before_filter :disable_nav, only: [:landing_page]

这篇关于除了某个动作之外,如何对所有内容进行局部渲染的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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