Most of My Assets Suddenly Return 404 After a Push to Heroku

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

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:

  1. gem 'rails_serve_static_assets' (it will solve the static assets problem) and
  2. gem 'rails_stdout_logging' (which the previous one depends on).

Rails 4: run application in production mode after assets precompile gives assets not found issue

Refer this discussion here - Most of my assets suddenly return 404 after a push to heroku
This is the exact issue we were facing.

Adding 12 factor gem: github.com/heroku/rails_12factor fixes this issue. (This gem is now required if you're running Rails 4+ on Heroku).
I tried adding gem 'rails_12factor' in the same repo you were working and this loads all assets just fine.

Basically this rails_12factor gem is a combination of 2 gems viz. rails_serve_static_assets and rails_stdout_logging. Gem rails_serve_static_assets just sets this configuration to true. This is generally in your config/environments/production.rb

config.serve_static_assets = true

So in general, if we are developing a Rails4 app and we deploy on our own servers (say a dedicated server and not heroku) then setting this flag config.serve_static_assets to true is sufficient and we don't need to add rails_12 factor or any other gems. Here is the code of rails_serve_static_assets gem which is used by rails_12factor gem.

module RailsServeStaticAssets
class Railtie < Rails::Railtie
config.before_initialize do
if Rails.version >= "4.2.0"
::Rails.configuration.serve_static_files = true
else
::Rails.configuration.serve_static_assets = true
end
::Rails.configuration.action_dispatch.x_sendfile_header = nil
end
end
end

GET http://0.0.0.0:3000/assets/images/ajax-loader.gif 404 (Not Found) error after login

well, there is one solution I can think of.

Looking at your gem file I see that you use the

gem 'jquery_mobile_rails'

I've searched in the github for this gem and I found 2 of them, one edited 1 year ago, and the 2-nd is edited 16 days ago.

I can think only that you use the first one, that is old, but the second one says clear that is for Rails 3.1

but at the same time, both gems requires to use gem 'jquery_mobile_rails' in the Gemfile to install it, might be you have the old gem, only this way I can explain why you have the wrong path for your image.

`/assets/images/ajax-loader.gif` 

this is the path for the image if I look in google-inspect you have this line in application.css but in the github repo you have no such line, so I think this is a line that the gem inserts in the application.css

So I would better download the new gem and paste it in the vendor/bundle folder just as you would run the bundle install --path=vendor/bundle command.

I will look further for the solution, but for now you should take a look at this jquery_mobile_rails gem.

p.s.

if you have now the path /assets/images/ajax-loader.gif that is wrong for rails 3.1 you might try to create this path on your own, just go to root/public/ and create this folder images and place that ajax-loader.gif inside this way the app should find the path.. or not, but it's worth to try it.



Related Topics



Leave a reply



Submit