Home>
What I want to solve

I want to hide only a specific page from the partial templates that are displayed on all pages.
If i apply this case, I want to hide the icon that is always displayed at the bottom right of the screen to move to the chat page because it has no meaning on the chat page.

*Image below
The icon (link to the chat page) at the bottom right of the image is displayed on all pages using a partial template.

I do not want to display the icon because the icon does not have meaning on the chat page that transitions after clicking the icon

Current code

application.html.erb

<!DOCTYPE html>
<html>
<head>
  <title>Chat</title>
  <%= csrf_meta_tags %>
  <%= csp_meta_tag %>
  <%= stylesheet_link_tag'application', media:'all','data-turbolinks-track':'reload' %>
  <%= javascript_include_tag'application','data-turbolinks-track':'reload' %>
</head>
<body>
    
    <%= render'layouts/header' %>
    <%= yield %>
    <%= render'layouts/chat_icon' %>
    <%= render'layouts/footer' %>
    
  <%= render'layouts/script' %>
</body>
</html>

Chat page


<% @messages.each do |message| %>
    
    <%= message.content %>
    
<% end %>


<%= form_with(model: @message, local: true) do |f| %>
  <%= f.text_field :content, class:'form-control' %>
  <%= f.submit'post', class: "btn btn-primary" %>
<% end %>

<script>
  // scroll to the bottom after page transition
  function scrollBottom(){
   var a = document.documentElement;
   var y = a.scrollHeight-a.clientHeight;
   window.scroll(0, y);
  }
  scrollBottom();
</script>

I tried working on something that can be hidden using css, but I couldn't implement it well.
I would appreciate it if you could teach me how to solve this matter. Thank you.

  • Answer # 1

    I tried working on something that can be hidden using css, but I couldn't implement it well.

    How about adding a controller name to the body?
    Personally, it was very easy to use.

    <body id="<%= controller.controller_name %>">
    :
    </body>

    By the way, conditional branching is also possible with action names, so refer to the following for details.

    Reference: https://qiita.com/lasershow/items/e7a75d3e1653c9ca39d8

Related articles