Difference between rake assets:precompile and rake assets:clobber - ruby-on-rails

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

Related

assets folder(images,stylesheets,javascripts files) is not working properly on the server in ruby on rails

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

Safely recompiling all assets on Rails 4 deployment?

Right now I have occasional issues with the Rails 4 asset pipeline that requires removing all assets and then recreating the assets.
During deployment, after pulling the latest from git, I refresh the assets by running, rake assets:clobber and then rake assets:precompile on my server. The problem is that during the time the assets are removed, the page gets served, not surprisingly, with no assets.
Is there anyway to force Rails to recompile all assets without having to run assets:clobber?
Here is what I usually do, when precompiling the assets.
// At a terminal, remove all assets from the file system
$ rm -rf public/assets
// Precompile the assets
$ rake assets:precompile
Always worked for me.
First run rake assets:precompile then run rake assets:clean. That will only remove old assets. https://github.com/rails/sprockets-rails/blob/master/README.md#rake-task

Rails Precompiling Custom Assets

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.

Can I still add changes to CSS after precompile?

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.

Assets don't seem to be compiling

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

Resources