Assets loading issue on Rails 5 app with Heroku
Asked Answered
E

1

5

I am facing asset loading issue in Rails 5 application deployed on Heroku.

App Configuration is,

ruby => ‘2.3.1’

rails => '~> 5.0.1'

When image is stored on path,

app/assets/home/image1.jpg

I am accessing it in view as,

= image_tag('/assets/home/image1.jpg’)

which is working properly in Development ENV, but not in Production ENV.

As per Heroku log,

ActionController::RoutingError (No route matches [GET] "/assets/home/image1.jpg")

If I am moving image directly to

app/assets/image1.jpg

then its working on Production ENV.

Please guide about it.

Thanks

Ehudd answered 16/6, 2017 at 12:8 Comment(0)
J
13

It looks like you assets are not compile on heroku.

Follow below code:

config/environments/production.rb

config.assets.compile = true then run commands:

RAILS_ENV=production rake assets:precompile

then push all compiled files with menifest file to heroku.

Jaffna answered 16/6, 2017 at 12:22 Comment(5)
Thanks. By setting config.assets.compile = true option, it works on heroku. And it works without pushing manifest file to heroku. Is it feasible to add 'public' directory to git commit code ?Ehudd
@Mansi yes. Accept and vote my answer if it works for you. ThanksJaffna
What file does RAILS_ENV=production rake assets:precompile go into?Twigg
@Twigg it creates some compressed files under public folderJaffna
better question -- @Jaffna is there a place that line of code can go in the production.rb so I don't have to run the command in terminal every time I change or add an asset?Twigg

© 2022 - 2024 — McMap. All rights reserved.