Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

no route matches for assets/images in Rails

Working on rails, images are not visible and giving 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 have used 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!

like image 526
vajapravin Avatar asked Jun 19 '12 07:06

vajapravin


2 Answers

Actually you cannot reference your image with /assets/home.png path. It will work in development mode, but in production all of your assets have a fingerprint in their filename (read this http://guides.rubyonrails.org/asset_pipeline.html#what-is-fingerprinting-and-why-should-i-care-questionmark)

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

like image 52
Chris Avatar answered Sep 19 '22 22:09

Chris


The lack of a fingerprint in the file request suggests that you are running this in development. I am also going to guess that this is an app upgraded from an older version of Rails.

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

Also, you do not need to precompile when in development mode.

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

If this images are in the correct location, it should work.

like image 44
Richard Hulse Avatar answered Sep 22 '22 22:09

Richard Hulse