Is there a way to have separate css folders for separate rails controllers? I have two themes I would like to combine. One for my home controller, when the user is not signed in. And one for my dashboard controller when the user is signed in. Both of these have multiple css and javascript files.
I know how to do this with one css file. Example: home controller only reads home.css.
But I would really like a folder for the home controller since I want to stay organized with multiple files.
Any help would be appreciated.
Just thought of a great idea after I posted this. This is for anyone else having this problem.
Remove the require all. So remove this line from application.js
//= require_tree .
And remove this line from application.css
*= require_tree .
Change to look like this in your application.html.erb
<%= stylesheet_link_tag "application", params[:controller], :media => "all" %>
<%= javascript_include_tag "application", params[:controller] %>
Add this to your config/initializers/assets.rb
%w( controller_one controller_two controller_three ).each do |controller|
Rails.application.config.assets.precompile += ["#{controller}.js", "#{controller}.css"]
end
**Replace controller_one, two, ect.. With you controller name.
Now for the cool part. Add a subfolder to stylesheets as your controller name. Mine was "home" in the example. Add your css files to it. Take your home.css (in your main stylesheets folder) and give it this code:
/*
* This is a manifest file that'll be compiled into application.css, which will include all the files
* listed below.
*
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
* or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
*
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
* compiled file so the styles you add here take precedence over styles defined in any styles
* defined in the other CSS/SCSS files in this directory. It is generally better to create a new
* file per style scope.
*
*= require home/freelancer
*= require home/bootstrap
*= require home/font-awesome
*/
Replace "freelancer" with what ever your file name is. My file name in my stylesheets/home folder, for this file, was freelancer.css
I believe there is a way to require all in subfolder, but I'm not positive. Like
*= require home/.
but not positive.