With Rails 3, how do I create a “link_to” reference that uses a pre-
exisiting token value instead of the record id? Is there a way to use
the URLHelpers to do this, or do I need to use the old style “link_to”
syntax with action, controller, id etc? The documentation doesn’t seem
to provide any pointers that don’t implicitly use :id.
I have a medical database where I’m trying to provide non-trivial
references to patient information. I calculate and store a hashed
token (:token) in the patient’s record. I want to
find_by_token(params[:id]), but I need to tell Rails how to create the
reference using the :token instead of the :id in the view.
With Rails 3, how do I create a “link_to” reference that uses a pre-
exisiting token value instead of the record id? Is there a way to use
the URLHelpers to do this, or do I need to use the old style “link_to”
syntax with action, controller, id etc? The documentation doesn’t seem
to provide any pointers that don’t implicitly use :id.
Two ways that I can think of. You can either override the 2 param
method, or if you create a route that looks like /foos/:token then the
corresponding help will expect you to pass a :token option to it.