Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails 5 assets return 404 in development

I know this question is asked a lot, but I'm losing my mind here. I started building an app using Rails 5. I deployed to AWS EB and set the env to development. But my assets aren't loading. Getting a 404. I implemented sprockets and require 'rails/all' in my application.rb file as well as running rake assets:precompile. I also tried all the config.asset configurations in development.rb:

config.assets_compile
config.public_file_server.enabled
config.assets.digest
config.assets.enabled

My nginx error log is full of the following for each of my assets. The path is wrong. I didn't put my assets in /var/app/current/public, I put them in /var/app/current/app/assets. At some point, I had it fetching from there (don't remember how) but it still didn't work:

2017/07/28 01:16:15 [error] 2994#0: *1387 open() "/var/app/current/public/assets/merck-logo.png" failed (2: No such file or directory), client: 76.218.103.88, server: _, request: "GET /assets/merck-logo.png HTTP/1.1", host: "merckcoupons-dev1.dv3ww3wmii.us-west-1.elasticbeanstalk.com", referrer: "http://merckcoupons-dev1.dv3ww3wmii.us-west-1.elasticbeanstalk.com/circular"

The crazy thing is that I just did this with another app not too long ago and have it open as a guide. I've been googling for hours and I can't figure it out. Any help would be appreciated!

like image 206
BooBailey Avatar asked Jan 02 '26 02:01

BooBailey


1 Answers

When referencing images using the image_tag helper only include the filename and no path. Rails will use the file in app/assets/images in development environment and then use public/assets/IMAGE_NAME_FINGER_PRINT.ext in other environments (after pre-compilation)

See: http://guides.rubyonrails.org/asset_pipeline.html#coding-links-to-assets

For example:

GOOD: <%= image_tag 'rails.png' %>

BAD: <%= image_tag '/assets/rails.png' %>

like image 187
house9 Avatar answered Jan 03 '26 15:01

house9



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!