Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails Routes - How to make them case insensitive?

Routes in Ruby on Rails are case sensitive. It seems someone brought this up before, and it has been labeled will not fix.

http://rails.lighthouseapp.com/projects/8994/tickets/393-routes-are-case-sensitive

That strikes me as unfortunate, as I don't really see any upside on my own application for routes to be case sensitive, while on the downside it creates a potential for confusion and a general appearance of lack of polish in my opinion.

What's the best way to make my routes case insensitive?

I found this tip on a Google search:

map.connect "web_feeds/:action", :controller  => 'web_feeds', :action => /[a-z_]+/i

This is clever, but it still leaves the web_feeds portion of the url case sensitive. I don't see any similar way around this, however, without entering in each possible combination of wEb_feEds manually, but that is obviously a horrible solution for any number of reasons.

like image 802
William Jones Avatar asked Feb 18 '10 20:02

William Jones


People also ask

IS routing case-sensitive?

on Jul 27, 2020. The standard is that the path in a URL is case-sensitive.

Are ASP NET routes case-sensitive?

Text matching is case-insensitive and based on the decoded representation of the URL's path.

What is restful routes in Rails?

The Rails router is responsible for redirecting incoming requests to controller actions. The routing module provides URL rewriting in native Ruby. It recognizes URLs and dispatches them as defined in config/routes.


2 Answers

Routes in Rails are case sensitive because URLs are case sensitive. From the W3C:

URLs in general are case-sensitive (with the exception of machine names). There may be URLs, or parts of URLs, where case doesn't matter, but identifying these may not be easy. Users should always consider that URLs are case-sensitive.

like image 123
John Topley Avatar answered Oct 19 '22 11:10

John Topley


I've just has the same problem, and solved it using middleware - have a look here:

http://gehling.dk/2010/02/how-to-make-rails-routing-case-insensitive/

Note: This only applies for Rails 2.3+

  • Carsten
like image 30
Carsten Gehling Avatar answered Oct 19 '22 12:10

Carsten Gehling