I need to dynamically render links to different routes in the view based on a parameter. Currently, this code below is functioning fine. But it makes use of url_for, which is a deprecated API call. Are there better ways to do this? is_admin? ? :"admin_#{name_of_route}_url" : :"#{name_of_route}_url" -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On 10/16/07, Tim Myers <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > I need to dynamically render links to different routes in the view based > on a parameter. Currently, this code below is functioning fine. But it > makes use of url_for, which is a deprecated API call. Are there better > ways to do this? > > is_admin? ? :"admin_#{name_of_route}_url" : :"#{name_of_route}_url"url_for isn''t deprecated; it''s passing a symbol to it that''s deprecated. You can avoid this by wrapping a send() around it: is_admin? ? send(:"admin_#{name_of_route}_url" : :"#{name_of_route}_url") Seems like there should be a better way. At least put that stuff in a helper method. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Bob Showalter wrote:> > url_for isn''t deprecated; it''s passing a symbol to it that''s > deprecated. You can avoid this by wrapping a send() around it: > > is_admin? ? send(:"admin_#{name_of_route}_url" : > :"#{name_of_route}_url") > > Seems like there should be a better way. At least put that stuff in a > helper method.Thanks, that helps with the deprecated warning! Yes, this is definitely in a helper because it is used throughout the site. Here''s what I went with: is_admin? ? send(:"admin_#{name_of_route}_url") : send(:"#{name_of_route}_url") -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On 10/18/07, Tim Myers <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Bob Showalter wrote: > > > > url_for isn''t deprecated; it''s passing a symbol to it that''s > > deprecated. You can avoid this by wrapping a send() around it: > > > > is_admin? ? send(:"admin_#{name_of_route}_url" : > > :"#{name_of_route}_url") > > > > Seems like there should be a better way. At least put that stuff in a > > helper method. > > Thanks, that helps with the deprecated warning! Yes, this is definitely > in a helper because it is used throughout the site. Here''s what I went > with: > > is_admin? ? send(:"admin_#{name_of_route}_url") : > send(:"#{name_of_route}_url")Oops, what I posted was a syntax error. Sorry! That looks much better. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---