Routes.rb: regular expression /i (case insensitive) doesn't work?

Dear all,

I have something like this in routes.rb:

map.connect ‘:test’, :controller => ‘help’, :requirements => { :test
=> /apple/i }

But then, the routing for URL “/apple” works but “/APPLE” does not!

Why doesn’t the i-for-case-insensitive work? Is this by-design or a
bug?

Thanks for any advice,
AK

Akira wrote:

map.connect ‘:test’, :controller => ‘help’, :requirements => { :test
=> /apple/i }

But then, the routing for URL “/apple” works but “/APPLE” does not!

Because Rails doesn’t use the regular expression as-is. It decides that
you always want the expression to be anchored at the start and end. The
code used is:

requirement_conditions = requirements.collect do |key, req|
if req.is_a? Regexp
value_regexp = Regexp.new “\A#{req.source}\Z”

So only the source string of your regular expression is used.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs