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
Related
I'm using Rails 5.0
Since I've done this command-line : ENV=production rake assets:precompile
when i change CSS I can see them in local instantly.
I have to kill the server, do this command-line again (ENV=production rake assets:precompile) in order to see the change I made.
Thaks for your help.
Rails requires you to pre-compile assets (css,js,etc) in production after you change anything in assets. However in development assets are compiled live by default.
If you want to compile assets live in production (Not Recommended):
then change config.assets.compile=false in config/environments/production.rb to:
config.assets.compile = true
That is Rails should recompile the assets when it detects that a new version of the source assets is there.
On production, you usually want to set it to false and handle asset compilation during deployment. For this, you have to run
RAILS_ENV=production bin/rails assets:precompile
Usually, if you deploy using Capistrano, it takes care of that.
Note: In rails 4 or earlier it was RAILS_ENV=production bin/rake assets:precompile but in Rails 5.x rake is merged into rails so you must use RAILS_ENV=production bin/rails assets:precompile.
In config/environments/development.rb,
I had config.assets.debug set to false instead of true.
i am new in ruby on rails, i have done some modification in assets file ( like add a new image file default2.png,some style file has be changed and some javascript file also changed).
I have uploaded all file on the server in assets folder then tried to precompile all assets with the help of following command rake assets:precompile and also tried rake assets:precompile RAILS_ENV= production
after that css was not working properly check box is not visible, some images are not displaying in page.
we try to rollback the precompile file using these steps
rm -fr public/assets
rake assets:clean
again we tried the rake assets:precompile and rake assets:precompile RAILS_ENV= production.
Problem is not resolved, i had tried with below links
database configuration does not specify adapter
Rollback rake assets:precompile
rails 4 asset pipeline vendor assets images are not being precompiled
then got error
**config.eager_load is set to nil. Please update your config/environments/*.rb fil es accordingly:
development - set it to false
test - set it to false (unless you use a tool that preloads your test enviro nment)
production - set it to true
rake aborted!
ActiveRecord::AdapterNotSpecified: '' database is not configured. Available: ["d efault", "development", "staging", "production"]
**
I was doing some mistake, if you want to add/edit new images, JavaScript and scss file in you are assets folders. you got same error then you have to do some changes...
change you java script file extension like: main.js to main.js.rb
change you scss style file extension
like: custom_style.scss to custom_style.scss.rb
compile below command
rake assets:precompile and rake assets:precompile RAILS_ENV= production
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
I've updated my Rails 3.2 app to 4.0 version and have stumbled upon one problem.
When I run the site with config.assets.compile = false option it doesn't load any assets. I've tried rake assets:precompile and it compiles assets at public/assets, but site doesn't load any of those. I've got application.js and application.css included in my layout, but when I check the source of the page, it's said that they are not found.
When I run the site with config.assets.compile = true everything works perfectly, but I've read that turning this off will result in greater performance, so I need to get it work.
Thanks in advance.
UPD: I've found that if I'm using this command RAILS_ENV=production bundle exec rake assets:precompile everything works. The question is why the rake assets:precompile command doesn't working?
UPD2: For those, who have the same issue, here's the explanation.
Regular rake assets:precompile compiles assets for application that runs in development mode. Specifying RAILS_ENV=production part in the beginning makes the command to compile assets for production mode, the bundle exec part is not required. So the final command looks like this: RAILS_ENV=production rake assets:precompile. Maybe it was obvious, but it took me a while to understand. Thanks.
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.