# Link\_to?

**URL:** <https://www.ruby-forum.com/t/link-to/114382>\
**Category:** Rails\
**Created:** [September 12, 2007, 1:12am UTC](https://www.ruby-forum.com/t/link-to/114382 "2007-09-12T01:12:37Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ccherlet](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/47e85d/32.png) [@ccherlet](https://www.ruby-forum.com/u/ccherlet)\
**Post date:** [September 12, 2007, 1:12am UTC](https://www.ruby-forum.com/t/link-to/114382/1 "2007-09-12T01:12:37Z")

</div>

How do I create a hyper link from the restaurant.name value below.

When this list is returned, I want each restaurant name to link to the  
show action.

Any help would be appreciated.

Thanks

\<% for restaurant in @restaurants %\>

\<%= h(restaurant.name) %\> \<%= link\_to 'show', :action =\> 'show', :id =\> restaurant %\>

\<% end %\>

|
| |

---

<div class="post-metadata">

**Author:** ![ccherlet](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/47e85d/32.png) [@ccherlet](https://www.ruby-forum.com/u/ccherlet)\
**Post date:** [September 12, 2007, 2:02am UTC](https://www.ruby-forum.com/t/link-to/114382/2 "2007-09-12T02:02:45Z")

</div>

On Sep 11, 6:12 pm, Craig C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> How do I create a hyper link from the restaurant.name value below.

\<%= link\_to restaurant.name, :action =\> ‘show’, :id =\> restaurant  
%\>

Jeff

> **[Hey Daddio!](http://softiesonrails.com)**
>
> Home of Hey Daddio Software

---

<div class="post-metadata">

**Author:** ![ccherlet](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/47e85d/32.png) [@ccherlet](https://www.ruby-forum.com/u/ccherlet)\
**Post date:** [September 12, 2007, 4:21pm UTC](https://www.ruby-forum.com/t/link-to/114382/3 "2007-09-12T16:21:42Z")

</div>

On 9/11/07, Jeff [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> On Sep 11, 6:12 pm, Craig C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> wrote:
> 
> > How do I create a hyper link from the restaurant.name value below.
> 
> \<%= link\_to restaurant.name, :action =\> ‘show’, :id =\> restaurant  
> %\>

\<% = link\_to h(restaurant.name), :action =\> ‘show’, :id =\> restaurant %\>

If you output a db value, be sure to wrap it in h() to prevent XSS and  
other nastiness.

---

<div class="post-metadata">

**Author:** ![ccherlet](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/47e85d/32.png) [@ccherlet](https://www.ruby-forum.com/u/ccherlet)\
**Post date:** [September 12, 2007, 6:40pm UTC](https://www.ruby-forum.com/t/link-to/114382/4 "2007-09-12T18:40:04Z")

</div>

Thanks!
