I'm programming a Rails application. I want to use an specific style in the whole HTML tag in the index page, but the rest of the pages should follow the application layout. So, in my controller I have:
def index
render layout: 'index_layout'
end
# All other actions follow this scheme
def any_other_action
end
The index layout has an specific piece of code that changes the styling:
<!-- Index layout -->
<html id="index_html">
...
<!-- Application layout (goes normally) -->
<html>
...
However, when I change from window to window through a link_to
tag in Rails, the layout is not being refreshed and the view remains with the id assigned in the previous page, for example, if I go from index to any other page, the html tag has the id index_html, and vice versa. However, if I perform a full refresh (by pressing F5 key), the layout is rendered properly. I tested in Mozilla Firefox and Chrome, in order to check if this was a browser peculiar issue, but the results are the same.
My server produces this output when I request index page, after I navigate to any other page through link_to
tag and then reload this new page:
Processing by HomeController#index as HTML
Rendering home/index.html.haml within layouts/index_layout
Rendered home/index.html.haml within layouts/index_layout (9.9ms)
Rendered layouts/_navbar.html.haml (13.6ms)
Completed 200 OK in 1254ms (Views: 1201.9ms | ActiveRecord: 0.0ms)
# Navigation with link_to tag, the index_html id is still appearing
Started GET "/community" for 127.0.0.1 at 2018-06-09 11:45:58-0500
Processing by HomeController#community as HTML
Rendering home/community.html.haml within layouts/application
Rendered home/_community_members_panel.html.haml (6.1ms)
Rendered home/_community_companies_panel.html.haml (8.1ms)
Rendered home/community.html.haml within layouts/application (41.5ms)
Rendered layouts/_navbar.html.haml (10.6ms)
Completed 200 OK in 110ms (Views: 101.0ms | ActiveRecord: 0.0ms)
# Full refresh of the page with F5 key, the index_html id doesn't appear, as it should.
Started GET "/community" for 127.0.0.1 at 2018-06-09 11:46:49 -0500
Processing by HomeController#community as HTML
Rendering home/community.html.haml within layouts/application
Rendered home/_community_members_panel.html.haml (5.6ms)
Rendered home/_community_companies_panel.html.haml (6.6ms)
Rendered home/community.html.haml within layouts/application (19.4ms)
Rendered layouts/_navbar.html.haml (8.4ms)
Completed 200 OK in 74ms (Views: 72.7ms | ActiveRecord: 0.0ms)
Can anyone give me some lights about what could be failing? My intuition is something about cache, but I can't find any answer that can help me. My Ruby version is 2.5.1 and my rails version is 5.1.6