Ruby / Rails - Hide Navbar & Footer on Root Page [duplicate]

ε祈祈猫儿з 提交于 2019-12-12 04:29:14

问题


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?


回答1:


try this in view 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

and next in view application.html.erb:

if root?
  #something html
end

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

in view application.html.erb

if current_page?(root_path)
  # your html
end


来源:https://stackoverflow.com/questions/39355210/ruby-rails-hide-navbar-footer-on-root-page

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!