Heroku Public Assets are Stuck - ruby-on-rails

Assets on Heroku are not updating with new code/assets/css.
I tried heroku rake assets:clean. I right clicked an image. I can see the code still has the old compiled asset hash in the public dir.
I even tried bumping the asset version.
Rails.application.config.assets.version = '2.0'
I am on Rails 5. This below line is in the Rails default production config. I didn't know apache handled serving static assets. Is that something new?
It also seems like Heroku is getting assets from somewhere else. Another server? If I delete the entire public dir right on the server, it still serves the assets on the website.
Comment
Disable serving static files from the /public folder by default since
Apache or NGINX already handles this.
config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present?

Are you seeing this output when you push to Heroku?
-----> Preparing Rails asset pipeline
Detected manifest.yml, assuming assets were compiled locally
That means it is still seeing a manifest file. Delete the public/assets directory to remove it with rake assets:clobber. Then you need to add these changes and then push to Heroku.

Related

When does Rails compile application.css?

I have a Rails app where I replaced a xxx.cs.scss file in assets/stylesheets/.
I restart Rails on my Mac using $ rails s.
And the old xxx.cs.scss is still in the application.css file according to my browser.
Why wouldn't the application.css file get re-compiled?
Thanks for the help!
Double check the asset compilation options in your environments/development.rb file to see if compilation is turned off.
Also, if you previously pre-compiled your assets (via rake assets:precompile) the compiled assets will take precedence over the on-demand compiled assets in your development environment. You may want to do rake assets:clean to get rid of any pre-compiled assets, then restart your local Rails server, and try again.

Rails generates wrong asset urls

rails beginner here
I am trying to set an app to production but having big issues with the asset pipeline. Under development every asset is generated under /assets/blabla.extension
However, I am running nginx and when running rake assets:precompile it creates assets under /public/assets as it should. But when I visit my app it generates urls like /application.css and not /assets/application-digestq12343.css as it should.
I think there is an easy fix to this problem.. but I cannot find it. Please help me!
Update:
From the documentation I read that Sprockets "default" is /assets but it certainly isn't in my application. I use the latest version of rails. Can the documentation be outdated?
http://edgeguides.rubyonrails.org/asset_pipeline.html
Even if I add config.assets.prefix = "/assets" to my production it would still mean that I would not load the assets since the digest would be missing.
I believe this is the same problem I was experiencing. Instead of using url()in your css (or scss), use asset-data-url() and add config.assets.enabled = true to your application config file. Then, rake assets:precompile before you push.

Most of my assets suddenly return 404 after a push to heroku

I have deployed this app (rails 3.2.11) a million times, I haven't messed with any settings, but now I'm greeted with this:
Why did this happen out of the blue? My conents of application.rb include config.assets.enabled = true - never had any issues.
In fact running it locally on port 3000 seems to not have any issues whatsoever.
After deploying to heroku this morning, it seems that it loads nothing that's inside /assets/
Interestingly, after copying the files over to try and just make a new app, git commit results in all the stuff you'd expect as well as a LONG list of these which I think might be related:
Edit: Interestingly enough SOME of the assets have loaded, like the logo and the background, but the rest as you can see return 404.
put line in config/environments/production.rb
config.assets.compile = true
it worked as it will compile the assets on runtime, just like in development environment, but its makes application slow, the best way is to either compile the assets locally in production environment with rake task(RAILS_ENV=production bundle exec rake assets:precompile) and commit your generated assets in public/assets and then do deployment. or, heroku run rake assets:precompile
I had this problem today with rails 4 on heroku. The article provided by #Jeff is a little bit old but, the gem repository has a good readme.
Summarizing, you will need to add two gems to your Gemfile:
gem 'rails_serve_static_assets' (it will solve the static assets problem) and
gem 'rails_stdout_logging' (which the previous one depends on).
Heroku released a gem to handle the assets without needing to turn off compilation or to manually compile.
https://devcenter.heroku.com/articles/ruby-support#static-assets
Just add this to your Gemfile and redeploy.
gem 'rails_serve_static_assets', group: [:production]
For Rails 4, use:
config.serve_static_assets = true
The default was false. We needed this after removing the rails_12factor gem.
Rails recommended that this setting config.serve_static_assets by default should be disabled i.e. set to false. Here is the default configuration in config/environments/production.rb generated in rails app
Disable Rails's static asset server (Apache or nginx will already do this)
config.serve_static_assets = false
So if you are setting it to true in your local app then that's still fine. But if you are deploying your app on Apache or ngix or anything other than heroku then its not advisable to make config.serve_static_assets=true in your production.rb config file. Here is the documentation from Rails guides.
config.serve_static_files configures Rails itself to serve static
files. Defaults to true, but in the production environment is turned
off as the server software (e.g. NGINX or Apache) used to run the
application should serve static assets instead. Unlike the default
setting set this to true when running (absolutely not recommended!) or
testing your app in production mode using WEBrick. Otherwise you won't
be able use page caching and requests for files that exist regularly
under the public directory will anyway hit your Rails app.
URL - http://guides.rubyonrails.org/configuring.html
To make the assets to load with the corresponding fingerprint of each file verify the configuration config/environments/production.rb has the instruction:
ruby
# Load assets with fingerprint behavior
config.assets.digest = true

Why rails respond with public/assets/application.js but not app/assets/javascripts/application.js in development mode?

I was testing turbo-sprockets gem and precompiled assets locally. Since then localhost:3000/assets/application.js always respond with public/assets/application.js file (not app/assets/javascripts/application.js).
Solution is to remove public/assets folder. Is it normal behaviour?
When you compile your assets with the production env, the generated assets are placed into public/assets. This is the first place Rails will search for assets : if you restart your app with development env, assets are already there and Rails won't search them in your app/assets directory anymore.
As stated in the documentation : "Any assets under public will be served as static files by the application or web server."
You're not supposed to precompile your assets on your development machine.

Rails 3 serve assets in production

Using Rails 3.2.2 and ruby 1.9.2 and I am not able to serve assets in production. We are running on apache. I've read some documentation and set :
config.serve_static_assets = true
config.assets.compile = true
in production.rb, and it doesn't seem to work. What else can I try? Or how can I get some debug info on where it IS looking.
Also, I went back to development, and went into assets/images and deleted .png files in order to intentionally break things in the development environment, but it didn't work, the images still show up. There must be some pre-compiling of assets, but where do they get stored, and how would I clear that? thanks
Usually, if you have Apache in front of your rails server, you would not want your application to compile assets in production. You probably want to pre-compile assets and have Apache serve them.
Compiled assets are stored in public/assets by default.
How all this comes together depends on the particulars of your configuration, which you have not shared. I would recommend reading the rails guides on the asset pipeline:
http://guides.rubyonrails.org/asset_pipeline.html
and in particular:
http://guides.rubyonrails.org/asset_pipeline.html#in-production
It heven has some examples of how to configure Apache.
In config/application.rb:
config.assets.enabled = true

Resources