Rails redirect/jump script?

I’m looking for some advice on how to write a jump script - something
that will look up a url in my database and redirect a cleaner url to
the one in the database.

For example:
url: http://www.amazon.com
jump url: http://www.mysite.com/jump/a

On 3/14/06, Michael N. [email protected] wrote:

http://lists.rubyonrails.org/mailman/listinfo/rails

Should be pretty easy.

class Jump < ActiveRecord::Base

name - string

url - string

end

class JumpController < ApplicationController
def jump
redirect_to_url Jump.find_by_name(params[:id]).url
end
end

Obviously that’s very basic and has no error handling, but you can
just make whatever changes you need. Then you can do
<%= link_to ‘Amazon’, :controller => ‘jump’, :action => ‘jump’, :id =>
‘a’ %>

Store some more info like the link name (amazon) and the jump name (a)
in the database if you’d like. You could throw the jump method in a
main controller or use routes so that the URLs appear as
http://mysite.com/jump/a

Pat

Thanks, just what I was looking for - didn’t know about the
redirect_to_url.