Forum: Ruby on Rails Route Regex Requirement not working properly

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Myron (Guest)
on 2007-06-12 12:43
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
(Guest)
on 2007-06-13 18:36
(Received via mailing list)
try

map.admissions 'admissions/downloads', controller => 'admissions'

before you define the stuff you just defined.

-L
This topic is locked and can not be replied to.