# Using join in a link\_to

**URL:** <https://www.ruby-forum.com/t/using-join-in-a-link-to/57631>\
**Category:** Rails\
**Created:** [April 12, 2006, 4:58pm UTC](https://www.ruby-forum.com/t/using-join-in-a-link-to/57631 "2006-04-12T16:58:16Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Paul\_Livingstone](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/7c8e57/32.png) [@Paul\_Livingstone](https://www.ruby-forum.com/u/Paul_Livingstone)\
**Post date:** [April 12, 2006, 4:58pm UTC](https://www.ruby-forum.com/t/using-join-in-a-link-to/57631/1 "2006-04-12T16:58:16Z")

</div>

I’ve got this:

\<% for tag in @tags -%\>  
\<%= link\_to tag.name, :controller =\> ‘archives’, :action =\> ‘tags’, :id  
=\> tag.safe\_name %\>  
\<% end -%\>

I want to use the .join(", ") trick to stick a comma between the links,  
where should I do this?

---

<div class="post-metadata">

**Author:** ![Paul\_Livingstone](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/7c8e57/32.png) [@Paul\_Livingstone](https://www.ruby-forum.com/u/Paul_Livingstone)\
**Post date:** [April 12, 2006, 5:12pm UTC](https://www.ruby-forum.com/t/using-join-in-a-link-to/57631/2 "2006-04-12T17:12:04Z")

</div>

Hello Paul,

> \<% for tag in @tags -%\>  
> \<%= link\_to tag.name, :controller =\> ‘archives’, :action =\> ‘tags’, :id  
> =\> tag.safe\_name %\>  
> \<% end -%\>
> 
> I want to use the .join(", ") trick to stick a comma between the links,  
> where should I do this?

\<%= @tags.collect { |tag| link\_to tag.name, :controller =\> ‘archives’,  
:action =\> ‘tags’, :id =\> tag.safe\_name }.join(", ") %\>

Not tested but it should work.

```
-- Jean-FranÃ§ois.
```

---

<div class="post-metadata">

**Author:** ![Paul\_Livingstone](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/7c8e57/32.png) [@Paul\_Livingstone](https://www.ruby-forum.com/u/Paul_Livingstone)\
**Post date:** [April 12, 2006, 5:12pm UTC](https://www.ruby-forum.com/t/using-join-in-a-link-to/57631/3 "2006-04-12T17:12:13Z")

</div>

Aha, got it… I used this instead.

\<%= @tags.collect {|tag| link\_to tag.name, :controller =\> ‘archives’,  
:action =\> ‘tags’, :id =\> tag.safe\_name}.join(", ") %\>

---

<div class="post-metadata">

**Author:** ![Paul\_Livingstone](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/7c8e57/32.png) [@Paul\_Livingstone](https://www.ruby-forum.com/u/Paul_Livingstone)\
**Post date:** [April 12, 2006, 5:12pm UTC](https://www.ruby-forum.com/t/using-join-in-a-link-to/57631/4 "2006-04-12T17:12:09Z")

</div>

Paul Livingstone wrote:

> I’ve got this:
> 
> \<% for tag in @tags -%\>  
> \<%= link\_to tag.name, :controller =\> ‘archives’, :action =\> ‘tags’, :id  
> =\> tag.safe\_name %\>  
> \<% end -%\>
> 
> I want to use the .join(", ") trick to stick a comma between the links,  
> where should I do this?  
> \<%= @tags.collect{|tag| link\_to… }.join(’, ') -%\>

---

<div class="post-metadata">

**Author:** ![Paul\_Livingstone](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/7c8e57/32.png) [@Paul\_Livingstone](https://www.ruby-forum.com/u/Paul_Livingstone)\
**Post date:** [April 12, 2006, 5:13pm UTC](https://www.ruby-forum.com/t/using-join-in-a-link-to/57631/5 "2006-04-12T17:13:25Z")

</div>

lol, thanks… we submitted that at the same time. I should’ve gave my  
brain a few more minutes to cook over before posting here.

Thanks again though!
