Heroku image not updating - ruby-on-rails

Just pushed a latest version of my Rails 4 app to Heroku which included a number of new images. All but one of the images has updated. The old images were overwritten with the new ones and hence have the same names.
I've tried wiping cache locally, wiping cache on Heroku, closing browser etc but nothing seems to work.
It works locally no problem.
Anyone have any suggestions to "force" all images to update?

Had simmiliar problem, using the following fixed the problem.
After logging onto Heroku
heroku run rake assets:clean
before pushing code to Heroku
RAILS_ENV=production bundle exec rake assets:precompile --trace
I was working on a couple of things at the time but my best understanding of how I got images to Heroku was as per above
Pierre

Related

Navbar from rails application disappears when deploying to Heroku

I have been building a Rails application that I am deploying to Heroku, I had installed a navbar to navigate around the app and it was working completely fine until recently. Now the navbar is not showing up on the application even though it still works perfectly when I try anything locally. I have tried rake assets:precompile, bundle install, and all the usual suspects. I don't know what to do exactly. I have attached screenshots of my app in testing and production. This is the image of the two apps. This error first turned up when I created an account on the production application on Heroku. The logs show this error
ActionController::RoutingError (No route matches [GET] "/assets/~bootstrap/scss/bootstrap")
So if a public/assets/manifest.yml(Rails 4 uses a file called public/assets/manifest-.json instead) is detected in your app, Heroku assumed you are handling asset compilation yourself and will not attempt to compile your assets. On both versions you can generate this file by running $ rake assets:precompile locally and checking the resultant files into Git.
This means that I ran rake assets:precompile locally, even just once, and then checked in that manifest file that would then need to run assets:precompile and check the results into git before every deploy. It's quite a subtle change that can catch people out.
Removing the public/assets/manifest.yml file from my git repo and re-deploying the app, so that asset compilation is done automatically by Heroku again solved the error.

Heroku rake command

I'm trying to push my Rails app to Heroku, and I'm at the point where I'm trying to create/migrate the database, but I cannot get the rake command to run. Here's the message I'm getting:
$ heroku run rake db:migrate
Running `rake db:migrate` attached to terminal... up, run.2439
bash: rake: command not found
I spent a lot of time getting Postgres set up on my local machine, and it's working fine (was able to run rake commands without issue, and the app is running locally), but I don't know why I'm getting this error when I try to migrate the heroku database.
Figured it out. Turns out I had an error when I tried to deploy the app to Heroku, so it was never deployed. I didn't realize this because I was trying to push a branch that was not the "master" branch to heroku, thinking it would be fine. I wasn't getting any errors on that push, but that's because heroku won't try to deploy anything other than the "master" branch. Once I pushed the "master" branch, I got a bunch of pre-compile errors. Once those were cleaned up, I the app was deployed properly and I was able to run the rake commands.
Long story short, make sure your app successfully deployed before trying to run rake commands.

Force Heroku to Recompile All Assets

I updated two images and now Heroku is serving one correctly but the other is still the old image. The output of the deploy logs show both images being precompiled with new hashes but the hash used to retrieve one of them (from the application.css file) is still the old hash and it's grabbing the old image somehow.
I'd like to force Heroku to recompile every asset and restart the server (essentially a fresh deploy). Currently it seems to "intelligently" only precompile the assets that it judges as being new. I tried doing rake assets:clobber and rake assets:precompile but it changed nothing -- still using the old hash to grab the old image version for one, but successfully getting the other. Any other options to try?
Expiring the assets manually worked -- changed config.assets.version = 1.0 to 1.1 in config/production.rb. Still not sure what happened, though.
You can now recompile assets without commiting anything.
heroku plugins:install heroku-repo
and then
$ heroku repo:reset --app=appname
$ git push heroku
Source: https://stackoverflow.com/a/9736959/3034747
This command used to accomplish the same thing, but it has been removed and no longer works:
$ heroku repo:rebuild -a appname
Gross, but make a small change and redeploy.
You have to actually redeploy because that's when asset compilation happens and your slug is compiled. Just restarting the server with heroku restart, changing config variables, or pretty much anything else won't build a new slug for you.
I just ran into this problem, and this was at least what solved it for me; YMMV.
Stuff like that can happen - why don't you try using heroku run rake assets:clean and heroku run rake assets:precompile to get the assets cleaned on the server

Heroku Won't Run "Rake" Commands

This literally just happened, and won't go away -- anyone had any similar experiences or a fix?
Many thanks!
You need to use heroku run to run your rake commands but don't do it with assets:precompile. That happens already when you deploy. If you need to precompile your assets, do it locally, commit the compiled files and deploy to heroku.

Heroku Assets Precompile

Today I was working with an application I've had running on Heroku for a few months now and in an attempt to get something working I ran in my development environment:
rake assets:precompile
When I committed my changes and pushed to Heroku, I get 500 errors on my request:
ActionView::Template::Error (jquery.flexslider-min.js isn't precompiled):
I'm at a bit of a loss as to what to do, I've tried a few things:
Lazily compile in production (which I really don't want to do):
Bundler.require(:default, :assets, Rails.env)
Specifically list all of the files that need to be "precompiled" (also don't really want to do this, doesn't seem very efficient):
config.assets.precompile += ...
So far I've simply done a rollback to my last working version. I'm currently stuck unable to push new code. Will be setting up a staging environment (like I should've done long ago) but not sure what to do next or what might fix this issue? Why didn't this throw an error before?
UPDATE
rake assets:clean
Appears to have resolved the problem, although I don't understand why. Can someone share some insight into this?
If you running Rails 4.0 or above, rake assets:clean has been replaced with rake assets:clobber.
However, there are some current problems with clean and clobber with regards to permanently deleting assets. You can follow the issue here. https://github.com/heroku/heroku-buildpack-ruby/issues/123
I'm willing to bet a compiled version/filename inside of manifest.yml in the public/assets folder was out of date/wrong.
If you've made changes to the flexslider.js file, you'll need to recompile with rake assets:precompile and push the updated version to github. I believe you can set the version of the assets inside of the manifest.yml file.
Also, I believe you can run heroku run rake assets:clean or heroku run rake assets:precompile.
I don't think it would be a good idea to precompile assets inside of heroku because of versioning and name conflicts/not stored in github.
You can clean the assets in heroku and push the repo again, so you wouldn't need to precompile locally and push to github, unless there was indeed an issue in the local compilation.
I'd also take a few minutes to read http://guides.rubyonrails.org/asset_pipeline.html
Another possibility is your file name is having issues with sprockets. Why not use the development version of the flexslider.js, rename it to something slightly more convenient, and allow sprockets to do the minification.
Found the solution in the GitHub thread:
increment the config.assets.version variable in
${project-root}/config/application.rb
Assets were refreshed after I'd added config.assets.version = '1.1' at the end of my config file.

Resources