Forum: Ruby on Rails Rails redirect/jump script?

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Michael N. (Guest)
on 2006-03-14 23:11
(Received via mailing list)
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:
jump url:
Pat M. (Guest)
on 2006-03-15 00:17
(Received via mailing list)
On 3/14/06, Michael N. <removed_email_address@domain.invalid> wrote:

Should be pretty easy.

class Jump < ActiveRecord::Base
  # name - string
  # url - string

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

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

Michael N. (Guest)
on 2006-03-15 07:23
(Received via mailing list)
Thanks, just what I was looking for - didn't know about the
This topic is locked and can not be replied to.