How to assign different stylesheets in a rails project?

I have a stylesheet application.css, defined in layouts/application.html.erb:

<%= stylesheet_link_tag "application" %>

However, there is a section of the site where the views will use a completely different stylesheet dashboard.css, which I defined in index.html.erb:

<head>
    <title>My title</title>
    <%= stylesheet_link_tag "dashboard" %>
..

If I do not delete the stylesheet_link_tag in the application layout file, conflicts arise that make the panel view visible strange. If I move the app’s stylesheet style tag tag to the _header.html.erb part that displays with each view in the non-panel section, as shown below, this does not work. How can I name them?

<%= stylesheet_link_tag "application" %>
<header>
     <div id="headercontainer">
..
+5
source share
3 answers

.

( ), . , .. users_controller, users.html.erb.

.

class UsersController < ApplicationController
  layout 'some_layout'
end

, , render.

def dashboard
  # some logic here
  render :layout => 'some_layout'
end
+5

yield application.html.erb head :

<head>
  <%= yield :head %>
</head>

content_for:

<% content_for :head do %>
  <%= stylesheet_link_tag "dashboard" %>
<% end %>

docs . ,

+5

I would suggest you define a second layout for the toolbar (app / views / layouts / dashboard.html.erb). From this layout links to panel style sheets. Then use this layout from the control panel or controller views.

Oh, just use some conditions to link different stylesheets in the same layout:

<%= stylesheet_link_tag(dashboard_views? ? "dashboard" : "application") %>

Just set dashboard_views? helper method to return true or false based on your views.

0
source

All Articles