[RUBY] [rails] Hide navbar and header only on TOP page

Overview

An event that stumbled while making an original app on rails. The part surrounded by the red frame below was called as a partial template. スクリーンショット 2020-10-14 21.51.51.png

The top page has the following structure, and I don't want to call the header, so I was wondering what to do. スクリーンショット 2020-10-14 21.47.49.png

How to call a partial template

Since I want to display all headers other than the top page, I render the partial template with ʻapplication.html.erb`.

erb:application.html.erb


<!DOCTYPE html>
<html>
  <head>~abridgement~</head>
  <body>
    <%= render "shared/header" %> <%#I'm calling the header here.
    <%= yield %>
    <%= render "shared/footer" %>
  </body>
</html>

I tried to divide the case by current_page?

This article If the current page is not the top page (root_path), I tried not to call the partial template.

erb:application.html.erb


<body>
  <% unless current_page?(root_path) %> <%#If the current page is root with unless, do not call
    <%= render "shared/header" %>
  <% end %>
  <%= yield %>
  <%= render "shared/footer" %>
</body>

Summary

When specifying the page to call the partial template, listed on the controller Fire a page called by JavaScript, there seems to be various means In my case, only one page is hidden, so I thought this method would be better.

If you have any reason why this method is not recommended, please let us know.

Recommended Posts

[rails] Hide navbar and header only on TOP page
[Ruby on Rails] Confirmation page creation
Rails migration column changes and so on.
[Ruby on Rails] Button to return to top
Resize or hide Button and EditText placed on the screen for each page
[Rails] Button to return to the top of the page
Ruby on Rails ~ Basics of MVC and Router ~
Determine the current page with Ruby on Rails
[Ruby On Rails] Description that allows only specific users to transition to the edit page
How to create a header or footer once and use it on another page