ruby-on-railsruby-on-rails-3

Changing a Routes Key ID, from /threads/ID to /threads/uuid


I have a threads model, that has Thread (id, uuid, title...)

Here is the path:

When the controller redirects: http://localhost:3000/threads/828b9a2ffc

In the logs I then see:

Started GET "/threads/828b9a2ffc" for 127.0.0.1 at Sat Jul 09 17:24:02 -0700 2011
  Processing by ThreadsController#show as HTML
  Parameters: {"id"=>"828b9a2ffc"}

The issue here is I don't want 828b9a2ffc to be the ID, I want it to interpruted as uuid in the parameters, so I should see:

  Parameters: {"uuid"=>"828b9a2ffc"}

How can that be made possible in the routes file?

Thanks


Solution

  • Maybe I'm missing something obvious but what's wrong with using a route like:

    match '/threads/:uuid' => 'threads#show', :via => :get
    

    in your routes.rb?