Forum: Ruby on Rails Routes Parameter manipulation

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.
B02f7055521940bf57a75101a7a48c2b?d=identicon&s=25 Yanir (Guest)
on 2009-03-03 00:01
(Received via mailing list)
I am creating a new site to replace an existing one and want to
preserve urls that people have bookmarked and appear in search
engines. My solution to this is create a route that takes a historical
url and pass that along to the controller of my choice with a new id
that was looked up in a table. This seems to work in theory but I am
stuck on something.

Here is my approach:

I want to take the url:  /category/123
lookup 123 in a table which will return a new id for my new catalog.
and send the user to a different controller with id 456 (or whatever
the looked up value is)

I have a method that is called in the route and will return a value.
The problem is passing the supplied id (named :cid in my code below).
I can't seem to pass the value that is in the url. Everything else
works. I can hard code the parameter to the catmap method and the
route works.

Routes.rb

  def catmap(cat)

    list ={'60'=>'2','61'=>'3'}

    return list(cat)
  end

class ApplicationController < ActionController::Base
...
  map.connect 'category/:cid',:controller => 'list', :action =>
'model', :id =>catmap(cid)
...
end
This topic is locked and can not be replied to.