Forum: Ruby on Rails routing: requiring requirements for non-existent params?

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.
81194a50c0f9bd95d7832a77fdf371bd?d=identicon&s=25 CSN (Guest)
on 2006-02-08 22:09
(Received via mailing list)
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
25e11a00a89683f7e01e425a1a6e305c?d=identicon&s=25 Wilson Bilkovich (Guest)
on 2006-02-09 04:14
(Received via mailing list)
On 2/8/06, CSN <cool_screen_name90001@yahoo.com> wrote:
>
> 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.
This topic is locked and can not be replied to.