Using join in a link_to


#1

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?


#2

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.

#3

Aha, got it… I used this instead.

<%= @tags.collect {|tag| link_to tag.name, :controller => ‘archives’,
:action => ‘tags’, :id => tag.safe_name}.join(", ") %>


#4

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(’, ') -%>


#5

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!