# Need help named route and link\_to

**URL:** <https://www.ruby-forum.com/t/need-help-named-route-and-link-to/178212>\
**Category:** Rails\
**Created:** [October 30, 2009, 9:31pm UTC](https://www.ruby-forum.com/t/need-help-named-route-and-link-to/178212 "2009-10-30T21:31:31Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![cswebgrl](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/edb3f5/32.png) [@cswebgrl](https://www.ruby-forum.com/u/cswebgrl)\
**Post date:** [October 30, 2009, 9:31pm UTC](https://www.ruby-forum.com/t/need-help-named-route-and-link-to/178212/1 "2009-10-30T21:31:31Z")

</div>

Hi,

In my application I’ve set up a custom route that works as long as I  
stay within the same model. This makes me think that I must have  
something wrong with the route.

map.agent ‘:agent’, :controller =\> ‘agents’, :action =\> ‘show’  
The resulting url is [http://www.domain.com/firstname-lastname](http://www.domain.com/firstname-lastname)

The problem that I have is creating a link\_to from a view outside of  
agents. I currently have this, but this will

\<%= link\_to\_unless(@property.agent.nil?, “view bio”,  
@property.agent.permalink) %\> generates this:  
[http://www.domain.com/properties/firstname-lastname](http://www.domain.com/properties/firstname-lastname)

Any ideas how to get this all to work correctly?

Thanks!

---

<div class="post-metadata">

**Author:** ![cswebgrl](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/edb3f5/32.png) [@cswebgrl](https://www.ruby-forum.com/u/cswebgrl)\
**Post date:** [October 30, 2009, 10:39pm UTC](https://www.ruby-forum.com/t/need-help-named-route-and-link-to/178212/2 "2009-10-30T22:39:24Z")

</div>

Hi,

On Fri, Oct 30, 2009 at 4:31 PM, Cs Webgrl  
\<removed\_email\_address@domain.invalid

> wrote:

> The problem that I have is creating a link\_to from a view outside of  
> agents. I currently have this, but this will
> 
> \<%= link\_to\_unless(@property.agent.nil?, “view bio”,  
> @property.agent.permalink) %\> generates this:  
> [http://www.domain.com/properties/firstname-lastname](http://www.domain.com/properties/firstname-lastname)

Can’t you do this? \<%= link\_to\_unless(@property.agent.nil?, “view bio”,  
{agent\_url, :name =\> @property.agent}) %\> or whatever your name would  
default to

> Any ideas how to get this all to work correctly?
> 
> ## Thanks!
> 
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).
> 
> >

–  
[www.abetaday.com](http://www.abetaday.com)

---

<div class="post-metadata">

**Author:** ![cswebgrl](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/edb3f5/32.png) [@cswebgrl](https://www.ruby-forum.com/u/cswebgrl)\
**Post date:** [October 30, 2009, 10:52pm UTC](https://www.ruby-forum.com/t/need-help-named-route-and-link-to/178212/3 "2009-10-30T22:52:26Z")

</div>

Gregory M. wrote:

> Can’t you do this? \<%= link\_to\_unless(@property.agent.nil?, “view bio”,  
> {agent\_url, :name =\> @property.agent}) %\>

Unfortunately that generates an error:

compile error  
/show.rhtml:138: syntax error, unexpected tASSOC, expecting ‘}’  
… :agent =\> @property.agent.permalink}) )…

---

<div class="post-metadata">

**Author:** ![cswebgrl](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/edb3f5/32.png) [@cswebgrl](https://www.ruby-forum.com/u/cswebgrl)\
**Post date:** [October 31, 2009, 3:23am UTC](https://www.ruby-forum.com/t/need-help-named-route-and-link-to/178212/4 "2009-10-31T03:23:30Z")

</div>

Gregory M. wrote:

> {:controller  
> =\> ‘agents’, :action =\> ‘show’, :agent =\> @property.agent.permalink} and  
> see  
> if that works.

Excellent! That worked. I had tried a variation of that, but must of  
missed something.

Thanks for your help!

---

<div class="post-metadata">

**Author:** ![cswebgrl](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/edb3f5/32.png) [@cswebgrl](https://www.ruby-forum.com/u/cswebgrl)\
**Post date:** [October 31, 2009, 12:34am UTC](https://www.ruby-forum.com/t/need-help-named-route-and-link-to/178212/5 "2009-10-31T00:34:49Z")

</div>

On Fri, Oct 30, 2009 at 5:52 PM, Cs Webgrl  
\<removed\_email\_address@domain.invalid

> wrote:

> compile error  
> /show.rhtml:138: syntax error, unexpected tASSOC, expecting ‘}’  
> … :agent =\> @property.agent.permalink}) )…

Sorry, it’s tough for me to guess with just this. As a check, you can  
replace {agent\_url, :agent =\> @property.agent.permalink} with  
{:controller  
=\> ‘agents’, :action =\> ‘show’, :agent =\> @property.agent.permalink} and  
see  
if that works.

–  
[www.abetaday.com](http://www.abetaday.com)
