Nathaniel Rand Nathaniel Rand - 1 year ago 84
Ruby Question

Ruby / Rails - Hide Navbar & Footer on Root Page

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?

Answer Source

try this in view application.html.erb :

<% unless controller.controller_name == "your_root_controller" && controller.action_name == "your_action" %>
<% 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"

and next in view application.html.erb:

if root?
  #something html

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

in view application.html.erb

if current_page?(root_path)
  # your html
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download