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. Thanks, Dave -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
> 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Nov 9, 3:14 am, dwormuth <dworm...-cIpcPs7DjqbWs/AcZQh2Cw@public.gmane.org> wrote:> 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. Fred> > 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. > > Thanks, > Dave-- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.