Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Assets loading issue on Rails 5 app with Heroku

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

like image 598
Mansi Shah Avatar asked Jun 16 '17 12:06

Mansi Shah


People also ask

How do I Precompile assets Rails in Heroku?

To compile your assets locally, run the assets:precompile task locally on your app. Make sure to use the production environment so that the production version of your assets are generated. A public/assets directory will be created. Inside this directory you'll find a manifest.

What is Rails assets precompile?

rails assets:precompile is the task that does the compilation (concatenation, minification, and preprocessing). When the task is run, Rails first looks at the files in the config.assets.precompile array. By default, this array includes application.js and application.css .

What does rake assets Clean do?

rake assets:clean removes compiled assets. It is run by cap deploy:assets:clean to remove compiled assets, generally from a remote server.

How does Rails asset pipeline work?

The asset pipeline provides a framework to concatenate and minify or compress JavaScript and CSS assets. It also adds the ability to write these assets in other languages such as CoffeeScript, Sass and ERB. Prior to Rails 3.1 these features were added through third-party Ruby libraries such as Jammit and Sprockets.


1 Answers

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.

like image 74
puneet18 Avatar answered Nov 13 '22 22:11

puneet18