Removing Precompiled Assets in Rails before Push to Heroku - ruby-on-rails

I have a Heroku app on Rails 4.0.8.
At some point early on, I realized that my CSS and JS changes wouldn't push to Heroku unless I ran rake assets:precompile and committed the new asset files before pushing (git push heroku master).
I've been doing those asset precompiles for about 14 months now, and I've amassed over 48mb in what appear to be old precompiled assets. However, when I remove them from public/assets manually, my site loses all of its CSS and JS.
How do I remove the old precompiled assets and get Heroku to start compiling on push?

Follow these steps:
rake assets:clean
git add .
git commit -m commit_name
git push heroku branch_name
This will clean your assets locally + pushing on heroku would precompile the assets.

Try the following code.
rake assets:clean

Related

Heroku is serving old assets for Rails 5 application

I've deployed a new version of a Rails 5 app on Heroku, running on cedar-14 stack. It didn't precompile while deploying, so I did heroku run rake assets:precompile manually. Still, I can see it includes old assets while requiring css and js files.
My files are in app/assets so it's not possible that directory isn't in assets compile path.
My config on application.rb and production.rb:
config.assets.compile = true
# I checked the environment variable, it responds to 'enabled',
# which would return true for the option.
config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present?
# Which I changed to expire old assets.
config.assets.version='1.1'
I tried these, but they didn't work:
$ heroku restart
$ heroku run rake assets:precompile
$ heroku run rake assets:clobber
The weird thing with these is that they do not affect assets in heroku server, which I checked with $ heroku run ls public/assets. Even after $ rake assets:precompile, even though it says this:
WRITING /app/public/assets/application-{VERY_LONG_HASH}.js
WRITING /app/public/assets/application-{VERY_LONG_HASH}.js.gz
WRITING /app/public/assets/application-{VERY_LONG_HASH}.css
WRITING /app/public/assets/application-{VERY_LONG_HASH}.css.gz
when I peek with the $ heroku run ls public/assets, I still see old assets staying there.
EDIT: I solved it by deleting all the local assets in public/assets, recompiling them with $ rake assets:clean && rake assets:precompile and including these assets in my git repository. Here is one concern:
Shouldn't heroku be responsible of compiling my assets on the fly? I think I shouldn't be compiling my assets everytime I deploy my application. Thanks.
Run on local
RAILS_ENV=production bundle exec rake assets:precompile
Next git add .
Next got commit -m"assets precompile"
Next git push origin yourBranchName
Deploy on heroku and you are done
You need to commit your changes first.
Then execute git push heroku yourbranch:master

Getting Rail4 asset-pipeline to heroku

My css & images are not making it to heroku. But I did what their tutorial said to do.
RAILS_ENV=production bundle exec rake assets:precompile
git add public/assets
git commit -m "assets added"
Then I heroku push and get
-----> Preparing app for Rails asset pipeline
Detected manifest file, assuming assets were compiled locally
so my assets pushed but there is still no css images or anything on my heroku app. Any ideas?
Try don't send your assets to heroku.
Remove public/assets from git:
git rm -r public/assets
git commit -m "Remove assets"
If still not working, on config/environments/production.rb set:
config.assets.compile = true
You also can try, on config/environments/production.rb set:
config.serve_static_assets = true
Heroku needs to have static assets, so each time you push to Heroku & change your assets, you should use this command:
rake assets:precompile

Is it possible to skip the asset precompile step for a single git push on Heroku?

Every time I deploy my Rails 3.2 project to Heroku, rake assets:precompile is run:
$ git push heroku master
...
----> Preparing app for Rails asset pipeline
Running: rake assets:precompile
Asset precompilation completed (189.17s)
...
Sometimes I want to make a push that I know does not change any assets, such as a quick hotfix to a controller. Is it possible to skip the asset:precompile step for a single git push to Heroku?
Thanks.
Sure! You'll need to create a manifest.yml in your_app/pubilc/assets directory.
The file can be blank. But ideally, you precompile everything locally, so deploys to Heroku would be much faster.
Make sure that you also committed the manifest.yml file when you're pushing to Heroku. Something like git add -f your_app/pubilc/assets/manifest.yml and a git push heroku master should suffice.
This worked for me. manifest.yml did nothing for me on my rails 4 project.
https://gist.github.com/Geesu/d0b58488cfae51f361c6
Just precompile locally with rake assets: precompile, check in the resulting assets that are in public/assets, and push to heroku.
This will automatically create the manifest-.yml or json file in your public/assets directory; then heroku will detect that and report Detected manifest file, assuming assets were compiled locally.
Note 1: Some people have a line in development.rb that makes these go to public/dev-assets instead; if so, you need to rename dev-assets to just assets)
Note 2: Make sure your .gitignore file is not excluding the public/assets directory.
In rails 4, create the file manifest-<md5 hash>.json instead of manifest.yml

Development of Rails with github after deployment on Heroku

I have a Rails 3.2.3 app that I host on github .Today I deployed it on Heroku.
During deployment, I made some changes to the Gemfile.
Run rake assets:precompile which generate a /public/assets folder.
I had to add and commit those change to local repository in order to
push to heroku by running git push heroku master
The deoployment was fine but now my development environment is like:
# On branch master
# Your branch is ahead of 'origin/master' by 2 commits.
Those are the changes I made for deployment on heroku (run precompile and some other stuffs) that I don't want to exist on my github repo. How do I do to continue my development (be able to push on github) and keep updating the change on heroku) ?
Clarification: public/assets is generated and should be added to local repo in order to push to heroku. So I can't put it in .gitignore But I don't want it to be pushed on github. What is the best practice?
I'm not sure why you're running rake assets:precompile in development. Are you debugging something? In general, it's best not to commit compiled assets to your repo since they are generated content.
On Heroku, you have the option to precompile your assets during slug compilation. This makes for a cleaner repo albeit a slightly slower deploy. Just remove public/assets so Heroku knows what to do. Also, make sure you add the following line to config/application.rb:
config.assets.initialize_on_precompile = false
https://devcenter.heroku.com/articles/rails3x-asset-pipeline-cedar

"application.css isn't precompiled" error on Heroku with remote assets on CDN

I'm getting the typical error on Heroku, that it appears the solution is to precompile locally and then commit to git.
ActionView::Template::Error (application.css isn't precompiled)
However I have my assets on Rackspace CloudFiles CDN using asset_sync and they are compiled fine, so I don't really want to also have to commit the compiled assets to git.
Any solution?
before you push your app to heroku run the following.
bundle exec rake assets:precompile
That will precompile all the necessary javascript and css.
If you are running the app on your computer after you precompile you will not see any css and js changes until you run.
bundle exec rake assets:clean
that will remove all precompiled files, you need to precompile every time you push your app.

Resources