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
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
lancecarlson-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Jun-13 14:35 UTC
Re: Route Regex Requirement not working properly
try map.admissions ''admissions/downloads'', controller => ''admissions'' before you define the stuff you just defined. -L On Jun 12, 4:43 am, Myron <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> 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 > > -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---