DanielFischer.com
2007-Aug-30 23:07 UTC
How to embed a route url inside of a helper, to return a path?
I am creating custom link_to''s and I''m trying to figure out how to embed a path inside of my method to return a custom link. for e.g Let''s say I need to do this => "http://someapi.com/submit?key=value&key=value&url=path_to_object" path_to_object should return something like ''www.mysite.com/path/to/ object'' I tried to do something like content_tag :a do, etc.. and I got to the point where I got this => link_to_api(user) "http://someapi.com/submit?key=value&key=value&url=user_path" What I found out was that user_path doesn''t get evaluated into an actual path like it does in a controller, or a view. So how would I actually turn ''user_path'' into the proper path that routes takes care of? (same functionality as link_to I guess). Thanks! --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Michael Wang
2007-Sep-01 00:26 UTC
Re: How to embed a route url inside of a helper, to return a path?
DanielFischer.com wrote:> I am creating custom link_to''s and I''m trying to figure out how to > embed a path inside of my method to return a custom link. > > > for e.g > > Let''s say I need to do this => > > "http://someapi.com/submit?key=value&key=value&url=path_to_object" > > path_to_object should return something like ''www.mysite.com/path/to/ > object'' > > I tried to do something like content_tag :a do, etc.. and I got to the > point where I got this => > > link_to_api(user) > > "http://someapi.com/submit?key=value&key=value&url=user_path" > > What I found out was that user_path doesn''t get evaluated into an > actual path like it does in a controller, or a view. So how would I > actually turn ''user_path'' into the proper path that routes takes care > of? (same functionality as link_to I guess). > > Thanks!Take a look at url_for. -- Michael Wang --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---