Urls are (for an unclear reason, generate different problems/no real advantage) defined case sensitive by w3.
What are my possibilities in routes.rb match case insensitively?
here the matching:
match '/:foo/library/:bar' => 'library#show'
Url Example: /europe/library/page4711
calls show action in library controller with { :foo => “europe”, :bar => “page4711” }
What I want are 2 things:
- the param value of :foo needs a .downcase so /Europe should be {
:foo => “europe” } - library should match case insensitively (ie. /Library, /LIBRARY,
/liBRarY all should match)
How do I do this in routes.rb?
Thanks!
Ok, to answer my own question:
There is no good way to do this within Rails routes.rb.
Here what I did:
For the first thing I created a before_filter in my controller:
For the second one I created a load balancer rule to get it lowercase to the rails app. Of course you can define a nginx/apache rule as well instead.
Edit: I found another solution for the second part because I disliked the pre-parsing/replacing of every url.
I made “library” to a symbol and wrote a constrained for it which only accept any form of the word “library”.
So the line in routes.rb looks like: