> 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.
In your model... def to_param code_to_generate_token end Once that's done then... non_trivial_named_path(@model_instance) will use the result of to_param automatically. Or, if you don't always want it just do... non_trivial_named_path(@model_instance.token) And remember that params[:id] is really the token in that case. -philip -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

