I want to print out a list of links separated by commas in Rails.
Heres what I've got:
<%= topics.each do |topic| %>
<a href="<%= topic.link %>" ><%= topic.name %></a>
,
<% end %>
Heres what I want:
<a href="thing_a">Thing A</a>,
<a href="thing_b">Thing B</a>,
<a href="thing_c">Thing C</a>
But right now I get an extra comma on the last iteration of the loop! What should I do?
One way of doing this is with map
then Array#join
:
<%= topics.map { |topic| link_to(topic.name, topic.link) }.join(',').html_safe %>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With