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?
Asked
Active
Viewed 1,099 times
0
-
1[How to detect if rails is at the root url](http://stackoverflow.com/questions/1924620/how-to-detect-if-rails-is-at-the-root-url) – Mick Sep 06 '16 at 18:08
1 Answers
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

Bartłomiej Gładys
- 4,525
- 1
- 14
- 24
-
The multiple solutions are appreciated. Would you recommend a specific one for production use? – Nathaniel Rand Sep 06 '16 at 19:34
-
if only for root i recommend for you last solution with `current_page?` method – Bartłomiej Gładys Sep 06 '16 at 19:34