I can't show static images on Ruby on Rails

I am trying to access:

http://localhost:3000/images/Header.png 

but I keep getting this error:

 Routing Error No route matches "/images/Header.png" with {:method=>:get} 

And here are my routes:

 ActionController::Routing::Routes.draw do |map| map.resources :worker_antpile_statuses map.resources :worker_antpiles map.resources :antcolonies map.resources :antpiles map.resources :clients map.connect ':controller/:action/:id' map.connect ':controller/:action/:id.:format' end 
+7
ruby-on-rails
source share
2 answers

The last two lines of your routes.rb are all routes that will match any previously inconsistent URLs. Comment on these two lines and it will work, what do you want to do when you use RESTful routing throughout your application.

See this great guide for everything you need to know about Rails routes.

+1
source share

Static assets must be in the / public folder, otherwise you will get a routing error. For a static image in http://localhost:3000/images/Header.png you want to place Header.png in RAILS_ROOT/public/images

When specifying any URL, Rails will check the file existing on the path from the RAILS_ROOT / public directory before trying to map any routes.

For example, when a Rails server receives a request for http://localhost:3000/users/1 , it will try to send the contents of RAILS_ROOT/public/users/1 . If the file does not exist, the route matching procedure is performed.

+15
source share

All Articles