Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Referencing different stylesheets in different views in Rails

I want to have a different set of stylesheets for the different parts of my Rails application. For example, I want to have a set of stylesheets for the landing page, a different set for the backend admin pages, and another set for the logged in account pages.

I've organized the stylesheets into folders with the names account, home, and admin, and I know how to specify in the application.css to just compile one folder.

*= require_self
*= require_tree ./account
*/

My question is, how do I specify that if the user is viewing the admin pages, or the home pages that the stylesheets in the admin or home folder should be the only style sheets that are referenced?

Thanks

like image 256
Arel Avatar asked Dec 21 '22 10:12

Arel


1 Answers

There is no way to create conditonal stylesheet creation, because on production it is compiled on deployment.

You must create separate stylesheets, for example one would be default application.css:

/*
 *= require_self
 *= require some_stylesheet
*/

Then separate, admin.css

/*
 *= require_self
 *= require some_admin_stylesheet
*/

Then in production enviroment configuration extend line:

config.assets.precompile += ['application.css', 'admin.css']

Next, create separate layout/or create conditional inclusion of:

<%= stylesheet_link_tag    "admin" %>
like image 110
raiis Avatar answered Mar 02 '23 16:03

raiis