I have a stylesheet, application.css
defined in layouts/application.html.erb
:
<%= stylesheet_link_tag "application" %>
However, there's a section of the site where the views will use a completely different stylesheet, dashboard.css
which I've defined in its index.html.erb
:
<head>
<title>My title</title>
<%= stylesheet_link_tag "dashboard" %>
..
Unless I remove the stylesheet_link_tag in the application layout file, there are conflicts which make the dashboard view weird. If I move the application layout stylesheet tag to a _header.html.erb partial which is rendered with every view in the non-dashboard section like below, it doesn't work. How must I call them?
<%= stylesheet_link_tag "application" %>
<header>
<div id="headercontainer">
..
you should use a yield statement in your application.html.erb in the head element as such:
<head>
<%= yield :head %>
</head>
then in your view, you would use a content_for tag:
<% content_for :head do %>
<%= stylesheet_link_tag "dashboard" %>
<% end %>
also read the rails docs on nested layouts. it'll teach you how to get fancy with this paradigm
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With