CSN
2006-Feb-08 21:09 UTC
[Rails] routing: requiring requirements for non-existent params?
With this route: map.connect ''items/:subject/:id'', :controller=>''items'', :action=>''show_redirect'', :requirements => {:subject => /.+/, :id => /\d+/} Is it possible to have it match these URLs: items/biology/123 items/chemistry/234 items/math/456 But not these: items/new items/list ... The problem is that :requirements only applies if that param exists. I''d like to make it so that that route only applies if all params do in fact exist. I''d do it with redirects in Lighty, but I want to send 301 redirects and I''m not sure what code redirect.url sends (probably 302). Thanks for any help! csn __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com
Wilson Bilkovich
2006-Feb-09 03:13 UTC
[Rails] routing: requiring requirements for non-existent params?
On 2/8/06, CSN <cool_screen_name90001@yahoo.com> wrote:> With this route: > map.connect ''items/:subject/:id'', > :controller=>''items'', :action=>''show_redirect'', > :requirements => {:subject => /.+/, :id => /\d+/} > > Is it possible to have it match these URLs: > > items/biology/123 > items/chemistry/234 > items/math/456 > > But not these: > > items/new > items/list > ... > > The problem is that :requirements only applies if that > param exists. I''d like to make it so that that route > only applies if all params do in fact exist. I''d do it > with redirects in Lighty, but I want to send 301 > redirects and I''m not sure what code redirect.url > sends (probably 302). > > Thanks for any help! > csn >This might be a crazy hack, but what happens if you change the route to be: map.connect ''items/:subject/:id'', :id => ''crazy'', :controller=>''items'', :action=>''show_redirect'', :requirements => {:subject => /.+/, :id => /\d+/} The idea being that :id defaults to a value that doesn''t match the requirements. Totally untested, may not work, etc.
Maybe Matching Threads
- Difficult process of restarting SCGI, Lighttpd, Apache, sessions
- undefined method `include''
- Building a conditions clause (for find) of multiple optional params?
- categories and admin/categories - different controllers and templates?
- Page caching feeds and cache file extensions