Heroku doesn't update assets modifications - ruby-on-rails

I'm using heroku to deploy my app in ruby on rails, but have a problem, when I deploy my app, heroku doesn't update with the modifications I made, before I compiled my assets. I solved my problem in localhost using a simple rake assets:clean but in heroku this doesn't solve what I make to back update when I modify my assets
config.assets.initialize_on_precompile = false
config.assets.initialize_on_precompile = true
Changed this but it doesn't work

There's a few things to do. The first is to redeploy
$ rake assets:clean
$ rake assets:precompile
$ git add .
... deploy to heroku
If it still doesnt work, it could be a caching issue, in which case, you can manually bump the version in config/application.rb and redeploy to expire all the previous assets
Ex:
config.assets.version = '1.2' # change to '1.3'

First of all. Heroku will pre-compile the assets for you when you deploy the app without assets as it will not find the manifest.yml. in assets.
To Make this work.
Remove all the assets files from the public folder in from local and heroku.
In production.rb
Make sure you have these code.
config.serve_static_assets = false
config.assets.compress = true
config.assets.digest = true
config.assets.compile = false
Set the assets.compile = true if you want the rails app to find asset for you if any asset is found. in precompiled. Ideally this option should be false.
config.assets.compile = true
Push these clean changes to heroku.

I had this same issue late last night, i found that after pushing to heroku it was disconnecting from git. Once I went through the GIT process again then pushed it to heroku everything updated. Not sure why it disconnects, but this has been my work around all day. Spent 2-3 hours trying to fix the root issue, but the work around is just faster.

Related

Rails 6 deployed on Heroku won't update Stylesheets

I built a Rails 6 app and deployed it to Heroku. But any changes I make to the stylesheet are not reflected. All the Heroku documentation and SO questions/answers appear to no longer be relevant to the current Rails setup in this regard. I could precompile the assets before pushing to heroku but I'd prefer not to. And actually I did find a "solution" but it feels more like a hack than a real solution. If I open config/initializers/assets.rb and change the statement:
Rails.application.config.assets.version = '1.0'
to
Rails.application.config.assets.version = '1.1'
then it will update the assets. But that means if I am experimenting with the look of the site I would be changing the version all the time. I mean if that's they way it's supposed to work I'll live with it, but it doesn't seem right. Anyone know a way to get Heroku to just update it on every push?
You've to compile the assets from the heroku end(i.e. in your server on Heroku), so after pushing your code to Heroku, run:
$ heroku run rake assets:precompile
# If above doesn't work
$ heroku run RAILS_ENV=production rake assets:precompile
Also, it's a good practice to add public/assets(or whatever folder that precompiles to) folder to your .gitignore file, so incase if you precompile assets in your local environment this will not mess up with your production env when you push to Heroku. But everytime you change some CSS and push to heroku, you'll need to precomile assets on Heroku end from the above command.

Ruby on Rails assets not being precompiled on Heroku

I have a project that works in the local development environment but breaks when it is uploaded to Heroku. When visiting my project on Heroku, I notice that I get 404 responses from the server saying that it could not find my css and js files. I have done some searching and found out that Heroku is not precompiling my assets. The project will work fine until Heroku puts my project to sleep. Upon waking the project in Heroku, the css and js are broken.
The project is using Rails 4.2.4, I have made sure to to include config.serve_static_assets = true in my config/application.rb and gem 'rails_12factor', group: :production in my Gemfile.
The css and js only breaks when Heroku puts the project to sleep due to inactivity. Does anyone know how to have Heroku automatically precompile assets when it is awaken from sleep?
I had similar issues before, my best bet was to precompile in local and then push to heroku. Configure your production.rb as follows:
config.serve_static_files = false
config.assets.compile = false
then in your console precompile as follows:
rake assets:precompile RAILS_ENV=production
This will precompile everything in public/assets commit your changes and push to heroku.
Also reset your assets cache for avoid any inconsistence:
rake assets:precompile RAILS_ENV=production
The above will force all your public/assets directory to rebuild when you run precompile command.
If your issue is with assets recompilation my answer should solve it, if you still have issues then you are doing something wrong or the issue does not have anything to do with assets precompilation.
We set the configuration values of above to false because now you are sending the precompiled files to the repo, so we do not serve static files nor fallback assets pipeline if something is missing, we are going everything in local.
Gemfile
gem 'rails_12factor', group: :production
application.rb
By default Rails 4 will not serve your assets. To enable this functionality you need to go into config/application.rb and add this line:
config.serve_static_assets = true
production.rb
config.serve_static_files = true
config.assets.compile = true
Command Line
bundle install
bundle exec rake assets:precompile RAILS_ENV=production
Make sure the images are in the /public folder.
Reference here

Heroku Rails 4 assets:precompile compiles all (also unchanged) assets

On every push to Heroku, all assets are precompiled, so not only assets that have changed. Asset precompilation thus takes more than 250 seconds. I tried all suggestions I found online, but I can't seem to fix it.
I have installed the rails_12factor gem as suggested by Heroku. Static assets are hosted on Cloudfront. We use Bower-Rails for front-end dependencies. Unicorn is the server on Heroku.
These are some settings in the production.rb environment:
config.serve_static_assets = true
config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect'
config.assets.compile = true
config.static_cache_control = 'public, max-age=31536000'
config.assets.compress = true
config.assets.digest = true
Has anyone experienced this as well? Or can anyone help me?
Have you tried running this before pushing to heroku?
bundle exec rake assets:precompile RAILS_ENV=production
Then do a git commit and git push heroku master
I wanted to post this as a comment but didn't have the rep ><

Ruby on Rails: Ran rake assets:precompile and now both local and heroku deployment don't include bootstrap

I was having issues deploying my project to a heroku server (Precompile fail). So I found this response, https://stackoverflow.com/a/13713753/2989437, and followed up on the advice. I added one line to my application.rb file:
application.rb
module FirstEdc
class Application < Rails::Application
config.assets.initialize_on_precompile = false # I added this line
...
end
end
I then ran the precompile command, committed the changes, and managed to deploy successfully to heroku. However, now my bootstrap/css appears to have stopped functioning both on the heroku deployment, and my local deployment.
I learned that I was supposed to add another line to my deployment.rb file:
deployment.rb
FirstEdc::Application.configure do
...
# Allows for local precompilling --added by Ian
config.assets.prefix = '/dev-assets'
end
So I added this, recompiled and redeployed, but to no avail.
Finally, I ran a rake assets:clean in an attempt to at least get my local deployment back to normal, but it did not work.
Any advice would be greatly appreciated. I'm reading more into the asset pipeline now, but I feel like this could be a cache problem or something. I'll update as I figure out what's going on.
edit. Just to clarify, I've tried removing both additions, running a rake assets:clean and rake assets:clean:all, but neither fix my local deployment.
I don't use config.assets.prefix in any of my apps and they work just fine with Heroku, so not sure what that's doing.
Try removing that line, then running rake assets:clean. Now your local server should be using the files as you change them. When you want to push, run rake assets:precompile first, then push.
If you want to make changes locally after that, run rake assets:clean again to get rid of the precompiled files on your local machine.
If Heroku detects any files in public/assets it will not attempt to precompile your assets again. This is by design.
So, you need to make a decision to either always precompile your assets with rake assets:precompile, or remove any files in public/assets before pushing to Heroku.
(The recommended way is to allow Heroku to precompile them during push)

Assets pipeline when updating to Rails 3.1 on Heroku

I've just upgraded my app on Heroku from Rails 3.0 to 3.1, and I'm trying to make the assets pipeline work. The main issue is that I can read from the heroku log the following kind of lines, for every asset:
2011-09-03T16:35:28+00:00 app[web.1]: cache: [GET /assets/border-a3c571a354b9381740db48aeebfaa63a.jpg] miss
If I understand the pipeline correctly, this should not be "miss" for every request I make from a browser, but it should be found in the cache.
Reading the Heroku docs you can find this explanation:
Rails 3.1 provides an assets:precompile rake task to allow the compilation penalty to be paid up front rather than each time the asset is requested. If this task exists in your app we will execute it when you push new code.
But how should that "assets:precompile" task be? I tried building a project with rails 3.1 from scratch to try to find out, but there is no such task in a bare project. Or am I missing something? How could I make that the assets are found in the cache? Maybe is just an issue with configuration.
These are the options of my production config file:
config.serve_static_assets = false
config.assets.compress = true
config.assets.compile = true # If I turn this off I get a 500 error and logs say that an asset isn't compiled
My application.rb has this line:
config.assets.enabled = true
Thanks a lot for your help!
Also, take a look at http://guides.rubyonrails.org/asset_pipeline.html#precompiling-assets
For faster asset precompiles, you can partially load your application
by setting config.assets.initialize_on_precompile to false in
config/application.rb, though in that case templates cannot see
application objects or methods. Heroku requires this to be false
I was wondering the same thing, but here's a tip to help figure out if your assets are live-compiling or not
run rake assets:precompile locally
make some changes to your css but do not rerun the rake task
git add, commit and push to heroku
If the changes you made in step 2 show up on heroku, then you know your app is live-compiling
Don't forget that you are now in charge of http caching since Varnish is no longer included on celadon, so you need to set up rack-cache and memcached yourself:
heroku doc on http caching
setup rack-cache with memcached on heroku
heroku docs on memcached
But yeah, I found this puzzling too
Can you try with config.serve_static_assets set to true and
config.action_dispatch.x_sendfile_header = "X-Sendfile"
added to your config/environments/production.rb file?
When you push your code to Heroku you should see the precompiling announced by the slug compiler AFAICT.
Make sure you are on the Heroku "Cedar" stack. Then Heroku will automatically precompile your assets during slug compilation.
Note: I'm still getting "cache misses" too, but I don't think that's really true because your app wouldn't work if your assets weren't compiled.

Resources