Forum: Ruby on Rails Using join in a link_to

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
E8b10683c74b1ef33b7fce9916a21290?d=identicon&s=25 Paul Livingstone (Guest)
on 2006-04-12 16:58
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?
13ea48f056b19349027d2f4a6921a46a?d=identicon&s=25 Jean-François (Guest)
on 2006-04-12 17:12
(Received via mailing list)
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.
Ad7805c9fcc1f13efc6ed11251a6c4d2?d=identicon&s=25 Alex Young (Guest)
on 2006-04-12 17:12
(Received via mailing list)
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(', ') -%>
E8b10683c74b1ef33b7fce9916a21290?d=identicon&s=25 Paul Livingstone (Guest)
on 2006-04-12 17:12
Aha, got it.. I used this instead.

<%= @tags.collect {|tag| link_to tag.name, :controller => 'archives',
:action => 'tags', :id => tag.safe_name}.join(", ") %>
E8b10683c74b1ef33b7fce9916a21290?d=identicon&s=25 Paul Livingstone (Guest)
on 2006-04-12 17:13
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!
This topic is locked and can not be replied to.