Simple Routing Gotcha

by Melvin Ram

Rails will always look at the public folder and serve that if it exists. If someone goes to yourdomain.com/monkey.html, it will look first at the public folder to see if there is a file that matches. If not, it will look for a route that matches. If no matching route exists, Rails will raise an exception (throw an error.)

Here’s the conversion that prompted this post:

glennfu: I have this route in my routes.rb file: map.pages ‘/*path’, :controller => “pages”, :action => “show”

glennfu: but it’s catching too much… like my favicon and some stylesheets.  How can I make it smarter?

melvinram: Are they (the favicon & stylesheets) in the public folder?

glennfu: yes

melvinram: Rails should look at the public folder first…

glennfu: perhaps that’s a clue, I’ll make sure they’re actually on the server…

glennfu: you spotted the problem, they’re actually not in the public folder!

glennfu: those files are missing

Leave a Comment