I have a separate scss file for each controller and I don’t import them all to the application.css file so that I can include controller specific stylesheet and js file in the layout.
So in the layout I do:
<%= stylesheet_link_tag "application" %>
<%= stylesheet_link_tag params[:controller], :media => "all" %>
<%= javascript_include_tag 'application' %>
<%= javascript_include_tag params[:controller] %>
But when I run rake assets:precompile I don’t get compiled assets for the controllers.
I looked for solutions on the web, but they all stated to add needed files to the config.assets.precompile staitment. And I don’t know what to put there so that all the assets in subfolders of app/assets/stylesheets and subfolders of app/assets/javascripts get compiled automaticaly.
UPDATE 1
OK, I will compile all them in one file, but there are two problems:
-
I have a _base.scss file containing all the needed variables and imports, and have renames application.css to application.css.scss so that i can import that file before everything else:
@import 'base'; @import 'style'; @import 'forms';
How do I need to do that with a manifest? Could not find a way to import the whole directory with scss itself.
- I have some different actions for same selectors in different controllers. What is the easyest way to separate those actions and define witch should be processed on a particular page?
This is a bad idea because it adds extra HTTP requests for each page load, requires a lot of extra files (most of which will be empty, there’s rarely going to be actual controller-specific CSS/JS), and ignores browser caching (cache the application.css/js once and forget about it).
Better to write your CSS/JS in such a way that you can include it all together and use the asset pipeline properly.