Reputation: 41929
I upgraded a Rails 3.0 app to Rails 3.1 which involved putting this
/*
*= require_self
*= require_tree .
*/
in the application.css file. However, there's an admin.css file that's now overriding the main app css file.
Is there a way to exclude the admin.css file from being included? In the admin section of the site I manually include the admin.css file but I need a way to exclude it from the user interface.
Upvotes: 26
Views: 20850
Reputation: 45094
Another solution is to have two directories in app/assets/stylesheets
, for example, a public
directory and an admin
directory.
Then, in app/assets/stylesheets/application.css
, you can change require_tree .
to require_tree ./public
.
You might have to do something similar on the admin side. I happen to be using the Administrate gem which knows where to find its own assets.
Upvotes: 4
Reputation: 2714
soluction is add in config/assets.rb
#config/assets.rb
Rails.application.config.assets.precompile += %w(*.svg *.eot *.woff *.ttf *.gif *.png *.ico *.swf *.xap masonry.pkgd.min.js jquery.colorbox-min.js i18n/jquery.colorbox-pt-BR.js admin.css)
And Add in app/views/layouts/_adm_layout.html.erb
#app/views/layouts/_adm_layout.html.erb
<%= stylesheet_link_tag 'admin', media: 'all', 'data-turbolinks-track' => true %>
Upvotes: -1
Reputation: 2041
You can use the stub
sprockets' directive in your manifest like this :
/*
*= require_self
*= require_tree .
*= stub admin
*/
This will exclude admin.css
and also ALL css required in it !!
So, if your admin.css
's manifest seems like this :
/*
*= require bootstrap
*= require_self
*/
the bootstrap.css
will also be excludes and no require
could fixe this ! Take care of this ;)
Upvotes: 104
Reputation: 8807
Similar question was asked earlier and you should check that one.
Sprockets uses manifest files to determine which assets to include and serve. These manifest files contain directives — instructions that tell Sprockets which files to require in order to build a single CSS or JavaScript file. With these directives, Sprockets loads the files specified, processes them if necessary, concatenates them into one single file and then compresses them (if Rails.application.config.assets.compress is true). By serving one file rather than many, the load time of pages can be greatly reduced because the browser makes fewer requests.
You can have as many manifest files as you need. For example the admin.css and admin.js manifest could contain the JS and CSS files that are used for the admin section of the application.
In particular, you can specify individual files and they are compiled in the order specified.
Example and more details can be found in this guide.
Thus, your new application.css would become:
/*
*= require styles
*= require layout
*/
/* Other styles */
Upvotes: 5