There are no route matches for assets / images in Rails

Work with rails, images are not visible and give an error.

Started GET "/assets/home.png" for 127.0.0.1 at 2012-06-19 12:23:24 +0530 Served asset /home.png - 404 Not Found (24ms) ActionController::RoutingError (No route matches [GET] "/assets/home.png"): 

I used the command

 rake assets:precompile 

production.rb

 config.assets.compress = true config.assets.compile = false 

application.rb

 config.assets.enabled = true config.assets.version = '1.0' 

Thanks for any help!

+6
source share
2 answers

In fact, you cannot link to your image using the path /assets/home.png . It will work in development mode, but during the production process all your assets have a fingerprint in their name (read this http://guides.rubyonrails.org/asset_pipeline.html#what-is-fingerprinting-and-why-should-i -care-questionmark )

This is why in applications with enabled pipeline assets, you need to reference all of your assets using helper methods. Read this document to learn about the various helpers available in the Ruby, JS, and Sass files: http://guides.rubyonrails.org/asset_pipeline.html#coding-links-to-assets

+6
source

The lack of a fingerprint in the file request suggests that you run this during the development process. I am also going to assume that this application is updated from an old version of Rails.

Any images must be in the folder / assets / images for the pipeline to work.

In addition, you do not need to precompile it in development mode.

Delete the public / assets folder, delete the tmp / cache / assets folder and restart the server.

If this image is in the right place, it should work.

+3
source

Source: https://habr.com/ru/post/918435/


All Articles