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"
On 10/16/07, Tim M. [email protected] 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.
Bob S. 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")
On 10/18/07, Tim M. [email protected] wrote:
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.