Appending something to a Rails route?

Hello railslist,

I’m trying to accomplish the following:

The URL http://localhost:3000/page/news/edit
should redirect to the URL http://localhost:3000/login

I’ve accomplished this by setting up a route like:

map.connect ‘page/:name/edit’, :controller => “login”

But this fails in the case of the following URL:
http://localhost:3000/page/news/article4000/edit

How can I set up a route that just detects if the URL starts with
/page and ends with /edit?
I’ve tried using route globbing, (by using an asterix symbol) but I
don’t really understand its use. I put it like:
map.connect ‘page/*/edit’, :controller => “login”
(…but this neglects the /edit)

Can or should I use regular expressions for this? And how do I fit that
in?
Thanks in advance,

Gijs N.

I think you need two routes for this particular task:
map.connect ‘page/edit’, :controller => ‘login’
map.connect ‘page/*/edit’, :controller => ‘login’

It’s not the strikingly elegant solution you probably wanted, but it
should work.


Jim K.
http://jim.eponym.com/
[email protected]

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs