# Route Regex Requirement not working properly

**URL:** <https://www.ruby-forum.com/t/route-regex-requirement-not-working-properly/106600>\
**Category:** Rails\
**Created:** [June 12, 2007, 10:43am UTC](https://www.ruby-forum.com/t/route-regex-requirement-not-working-properly/106600 "2007-06-12T10:43:59Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![myron](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e47774/32.png) [@myron](https://www.ruby-forum.com/u/myron)\
**Post date:** [June 12, 2007, 10:43am UTC](https://www.ruby-forum.com/t/route-regex-requirement-not-working-properly/106600/1 "2007-06-12T10:43:59Z")

</div>

I’m trying to get my routes to work properly. Here’s how I’m defining  
one of my routes:

map.downloads ‘:category/downloads’, :controller =\> ‘downloads’, :action  
=\> ‘list\_downloads\_for\_category’, :requirements =\> {:category =\>  
DownloadableFileCategory.category\_regex}

And here’s the method definition for  
DownloadableFileCategory.category\_regex:

def self.category\_regex  
regex\_str = “”  
for category in DownloadableFileCategory.find(:all)  
regex\_str += category.category.downcase  
regex\_str += “|”  
end

```
Regexp.new(regex_str.chop, Regexp::IGNORECASE)

```

end

This creates a regex such as /admissions|jobs/i so that the url  
/admissions/downloads maps to the list\_downloads\_for\_category method  
with params[:category] = “admissions” and /jobs/downloads maps to the  
same method with params[:category] = “jobs”. That part works correctly.

The part that’s not working is the Regexp::IGNORECASE option. URLS such  
as “/Admissions/downloads”, “/ADMISSIONS/downloads” do not match this  
route even though I’ve set the regex to ignore case. I tried testing  
just the regex in script/console and it worked just fine. It just  
doesn’t work when trying to match the URL.

Why doesn’t this work?

Thanks,  
Myron

---

<div class="post-metadata">

**Author:** ![myron](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e47774/32.png) [@myron](https://www.ruby-forum.com/u/myron)\
**Post date:** [June 13, 2007, 4:36pm UTC](https://www.ruby-forum.com/t/route-regex-requirement-not-working-properly/106600/2 "2007-06-13T16:36:23Z")

</div>

try

map.admissions ‘admissions/downloads’, controller =\> ‘admissions’

before you define the stuff you just defined.

-L
