Welcome to Working With Rails


Discussion Forums

Discuss all things Ruby on Rails with perhaps the web's most vibrant group of Ruby on Rails enthusiasts.
Inserting ID to URL
3 Posts
Inserting ID to URL

I am creating a tinyurl clone based off of Robby Rusell's Rubyurl. The purpose of the app is to not only shrink the size of a URL, but to also track how the new URL is being used. For example, if I wanted to create a new tiny URL to be used on behalf of one of my clients, I'd want to somehow pass a client ID to the new tiny URL so that it would look something like this: www.rubyurlclone.com/clientID/random_token

Question: how do I insert that clientID? Having a hard time wrapping my brain around this one.

Thanks! n'cho

Well, doing anything with how your routes are generated would be handled in the routes.rb file. A simple example(not realistic without more detailed info):

in routes.rb: map.connect ':clientID/:random_token ',

 :controller => 'my_controller', 
 :action => 'my_action'

in view: link_to 'my_link', :controller => 'my_controller', :action => 'my_action', :clientID => params[:client_id], :random_token => params[:random_token]

I hope this gets you headed down the right path.

I would map a root dispatch_controller to root (/) and glob the routes, the first being client id, the second being the generated token

Sr. Ruby & Rails Consultant For Hire
Sign In To Rate Post
3 Posts
Login to add your message