How can I precompile all css files in a particular folder? - ruby-on-rails

To precompile all css files in a project I could add this to production.rb:
config.assets.precompile << '*.css'
But how can I add only css files in a particular folder?

Add all stylesheets into your app/assets/stylesheets/application.css:
/*
*= require_self
*= require_tree dir_one
*= require_tree dir_two
*/
Then they will be precompiled. I think this is the preferred way over using config.assets.precompile.
If you really want to use it, this SO question should help: How do I use config.assets.precompile for directories rather than single files?

Related

How to store javascript in app/controllers?

I would like to keep Javascript controllers (Angular) next to Rails 4 controllers, in the same folder. I added this line to the config/initializers/assets.rb
Rails.application.config.assets.paths << Rails.root.join('app', 'controllers')
And restarted server (development env), but it didn't help. Javascript files are written in Coffee and work when in standard assets/javascripts folder.
Solved by adding one line in assets/javascripts/application.js
//= require_tree ../../controllers
I's because default require_tree . doesn't autoload all javascript files in asset pipeline, but only those in the "dot" folder of application.js, which is standard javascripts folder.
add this line to the application.js
//= require_directory .
It will include all js files in the app/assets/javascript directory recursively

Rails: do not allow compile assets

Is any way to prevent the compiling of specific *.scss files from assets/stylesheets? I need to keep those files in assets not public directory
you can remove
*= require_tree .
line from application.scss and require only the files you want to compile.

Rails precompile assets in production - different than in development

I have in my application.css this:
*= require_self
*= require styles
*= require custom
*= require paggination
*= require colorbox
*= require registration
*= require ../vendor/dark
On development everything is OK but when I move to production, also some other assets must be precompiled because site looks different in production.
Does Rails precompile also other css files from assets folder, not only this required? I have many other css in assets folder.
Rails by default only precompiles application.css
If you need to add individual css files, maybe if you need specific styles on certain pages you need to add them like this.
# in config/production.rb
# application.js, application.css, and all non-JS/CSS in app/assets folder are already added.
config.assets.precompile += %w(frontpage.css login.css)
Note: You list only the css ending even though it's a scss file you have.
Then you can reference your stylesheets in your view files.
<%= stylesheet_link_tag "frontpage" %>
Edit: And of course don't forget to do
bundle exec rake assets:precompile RAILS_ENV=production

Rails assets pipeline - not precompiling subdirectory

In both assets/stylesheets and assets/javascripts, I have a folder called admin, which has a handful of appropriate Coffeescript and SASS files.
$ cat app/assets/javascripts/admin.js
//= require jquery
//= require jquery_ujs
//= require_tree ./admin
$ cat app/assets/stylesheets/admin.css
/*
*= require_self
*= require_tree ./admin
*/
$ cat config/application.rb | grep 'assets.paths'
config.assets.paths << "#{Rails.root}/app/assets/stylesheets/admin"
config.assets.paths << "#{Rails.root}/app/assets/javascripts/admin"
After precompiling, the admin folders (and their contents) are nowhere to be seen in public/assets.
I'm probably making a fundamental mistake here; I've done very little playing with the pipeline besides the basics of images, application.js etc.
Can anyone point out what I'm doing wrong?
From what i can see, they are manifests. By default only application.css and application.js are precompiled. Other need need to be added.
You need to add them to the production.rb environment as follows (comment is from the file itself):
# Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added)
config.assets.precompile += %w( admin.css admin.js )
Also, you can ditch the config.assets.paths in your application.rb, because those paths are loaded by default.

Asset pipeline not precompiling sass

I've updated my app to use the rails 3.1 asset pipeline (I think). I can compile .css files but not css.scss. I am running the sass-rails gem but nothing seems to work.
What should I check? Sorry, I don't know exactly what info I should supply here to help debug. I can edit this...
EDITS:
My .scss file contains:
/*
*= require_self
*= require_tree .
*/
edit:
see Sprockets::CircularDependencyError in Store#index
Thanks,
Rim
Remember that css.scss files need to be included, not imported like the rest:
So: Turn you application.css into an application.css.scss, and do like this in it:
/*
*= require ./normal/custom.css
*= require_self
*/
#import "normal/design/control_panel";

Resources