Ruby/Rails-隐藏导航栏和根页面上的页脚 [英] Ruby / Rails - Hide Navbar & Footer on Root Page

查看:101
本文介绍了Ruby/Rails-隐藏导航栏和根页面上的页脚的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只想在根页面上隐藏导航栏和页脚.我正在使用RoR.我目前在我的应用程序文件中有导航栏,以防止重复.我在我的应用程序控制器上假设一个过滤器?

I would like to hide the navbar and footer on the root page only. I am using RoR. I currently have my navbar in my application file to prevent repetitiveness. I assume a filter on my application controller?

推荐答案

在视图application.html.erb中尝试:

<% unless controller.controller_name == "your_root_controller" && controller.action_name == "your_action" %>
  <nav> 
       #something
  </nav>
<% end %>

或者甚至您可以在助手中创建类似这样的方法:

or even you can make in helper something method like this:

def root? 
 controller.controller_name == "your_root_controller" && controller.action_name == "your_action"
end

和下一个视图application.html.erb:

if root?
  #something html
end

或者您也可以使用current_page?方法,并通过这种方式:

or you can also use current_page?method, and in this way:

在视图application.html.erb

if current_page?(root_path)
  # your html
end

这篇关于Ruby/Rails-隐藏导航栏和根页面上的页脚的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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