I am working in rails project. I created a header and footer and added to all pages in layouts/application.html.erb file. Now I want to remove it from a particular page.
Asked
Active
Viewed 306 times
0
-
1Just found the best answer in: https://stackoverflow.com/questions/5131073/how-to-hide-footer-layout-on-a-particular-page/65418059#65418059 – Feb 09 '21 at 18:26
1 Answers
0
Each page of a rails app is an action
nested inside a controller
.
You can see the current controller_name
and action_name
by adding the below to a view:
<%= controller_name %>
<%= action_name %>
To not render header
or a footer
for a specific page (controller
or action
or both) you can make the rendering conditional:
application.html.erb
<body>
<% unless controller_name = "static_pages" %>
<%= render "layouts/header" %>
<% end %>
<%= yield %>
<% unless action_name = "landing_page" %>
<%= render "layouts/footer" %>
<% end %>
</body>
Alternatively as a more sophisticated approach you can create a separate layout file for a specific controller: https://guides.rubyonrails.org/layouts_and_rendering.html#finding-layouts

Yshmarov
- 3,450
- 1
- 22
- 41