Replacing :id from routes without breaking the convention

210 Views Asked by At

I just replaced the :id on the resource routes in rails 3 for a hash generated. I'm annoyed by the fact that I'm writing less conventional code (e.g. a link_to edit_user_path(@user) is now written as link_to '/users/#{@user.user_hash}'). So I'm wondering, is therea smarter way to do this?

1

There are 1 best solutions below

0
On BEST ANSWER
class User < ActiveRecord::Base
  def to_param
    user_hash
  end
end

and edit_user_path(@user) will work properly for you