# Dynamic named routes in the view

**URL:** <https://www.ruby-forum.com/t/dynamic-named-routes-in-the-view/117430>\
**Category:** Rails\
**Created:** [October 16, 2007, 8:25pm UTC](https://www.ruby-forum.com/t/dynamic-named-routes-in-the-view/117430 "2007-10-16T20:25:59Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![enchanter](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/ce7236/32.png) [@enchanter](https://www.ruby-forum.com/u/enchanter)\
**Post date:** [October 16, 2007, 8:25pm UTC](https://www.ruby-forum.com/t/dynamic-named-routes-in-the-view/117430/1 "2007-10-16T20:25:59Z")

</div>

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"

---

<div class="post-metadata">

**Author:** ![enchanter](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/ce7236/32.png) [@enchanter](https://www.ruby-forum.com/u/enchanter)\
**Post date:** [October 16, 2007, 8:53pm UTC](https://www.ruby-forum.com/t/dynamic-named-routes-in-the-view/117430/2 "2007-10-16T20:53:02Z")

</div>

On 10/16/07, Tim M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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.

---

<div class="post-metadata">

**Author:** ![enchanter](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/ce7236/32.png) [@enchanter](https://www.ruby-forum.com/u/enchanter)\
**Post date:** [October 18, 2007, 5:24pm UTC](https://www.ruby-forum.com/t/dynamic-named-routes-in-the-view/117430/3 "2007-10-18T17:24:46Z")

</div>

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")

---

<div class="post-metadata">

**Author:** ![enchanter](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/ce7236/32.png) [@enchanter](https://www.ruby-forum.com/u/enchanter)\
**Post date:** [October 18, 2007, 5:30pm UTC](https://www.ruby-forum.com/t/dynamic-named-routes-in-the-view/117430/4 "2007-10-18T17:30:01Z")

</div>

On 10/18/07, Tim M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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.
