I have a custom application_admin.css.scss under app/assets/stylesheets
and I have this line in my config/environments/production.rb file
config.assets.precompile += [%w(application_admin.css)]
When I run bundle exec rake assets:precompile the custom stylesheet doesn't compile
I came across this post but I already have what they suggested.
Rails Assets custom manifests are not precompiling
What else should I check?
First, you don't need to use both [] and the %w(). Try just:
config.assets.precompile += %w( application_admin.css )
which is the equivalent of:
config.assets.precompile += ['application_admin.css']
Second, since you are precompiling for your production environment you want to run:
RAILS_ENV=production bundle exec rake assets:precompile
Just:
bundle exec rake assets:precompile
runs it for your development environment by default. You will want to run this in each environment you want to precomplie your assests in.
Related
I am using rails admin. My application is working perfectly in local but when its throwing the above error while configuring in live
config/initializers/assets.rb
Rails.application.config.assets.precompile += %w(*.css *.js ckeditor/*)
But when I precompile my assets, nothing is compiled.
You can try to add to config/initializers/assets.rb:
Rails.application.config.assets.precompile += %w( rails_admin/rails_admin.css
rails_admin/rails_admin.js )
And if you are deploying to Heroku, you can check their assets troubleshooting: https://devcenter.heroku.com/articles/getting-started-with-rails6#rails-asset-pipeline
Or if you are not deploying to Heroku
npm -g i yarn
RAILS_ENV=production bundle exec rails assets:precompil
RAILS_SERVE_STATIC_FILES=true bundle exec rails s -e production
Possible Solution
install yarn
install webpacker by running
RAILS_ENV=production bundle exec rails webpacker:install
production.rb
config.assets.compile = true
Now precompile your assets
RAILS_ENV=production bundle exec rails assets:precompile
Can anyone please tell me the difference between rake assets:precompile and rake assets:clobber. really its a great confusion.
You can precompile the assets in app/assets using rake assets:precompile, and remove older compiled assets using rake assets:clean. The rake assets:clean task allows for rolling deploys that may still be linking to an old asset while the new assets are being built.
If you want to clear public/assets completely, you can use rake assets:clobber.
rake assets:clean # Remove old compiled assets
rake assets:clobber # Remove compiled assets
rake assets:precompile # Compile all the assets named in config.assets.precompile
Note: rake assets:clobber also removes the assets directory completely.
To get the info on any rake tasks try this :
rake --describe | grep assets
This returns all the answers.
rake assets:clean[keep]
Remove old compiled assets
rake assets:clobber
Remove compiled assets
rake assets:environment
rake assets:precompile
Compile all the assets named in config.assets.precompile
the command rake assets:clobber removes/deletes all compiled assets. Whilst the command rake assets:precompile creates the compiled assets listed on parameter config.assets.precompile.
Please have a read on Rake's documentation for further information on it
Once I've done bundle exec rake assets:precompile RAILS_ENV=production
It seems that it created something like application-e24jrjf834jg93bwuk13uy5gfd1y24f.css
Then when I access to the page, that is called from my app.
In development mode, I could add changes to just to css file and it applied.
In production mode, can I still add little changes to css?
If possible, how?
If you have set config.assets.initialize_on_precompile to true in your production.rb file then all you need to do is restart your server. Otherwise just delete the precompiled assets by running bundle exec rake assets:clean and precompile assets again bundle exec rake assets:precompile RAILS_ENV=production.
I want to manually precompile some assets in my dev environment (to check the content of the compiled js and css files) from the command line.
I am running
RAILS_ENV=development bundle exec rake assets:precompile
but my js and css are not compiled in the public/assets folder, only the images are. Any idea why that may be happening?
Try adding this to your config/environments/production.rb :
config.assets.precompile += %w( *.css *.js )
I keep getting the error saying that the application.css isn't compiled.
I tried:
rake assets:precompile
And it didn't work, I even tried to run it with RAILS_ENV=production and still it didnt' work.
When I change my production.rb and set the config.assets.compile = true then it worked.
WHy isn't the manual compiling working?
This is a great RailsGuide on the Asset Pipeline:
http://guides.rubyonrails.org/asset_pipeline.html
you need to set RAILS_ENV before running "precompile", e.g.:
RAILS_ENV=production bundle exec rake assets:precompile
See also:
rake assets:precompile doesn't work (rails 3.1.1)
Rails 3.1 asset precompilation - include all javascript files