Topic: Comma Separation
In my web app I have a one-to-many relationships so a ticket can belong to many departments, and so when displaying the list of departments I would like to separate them with commas, I have a loop doing this but there must be a better way, if anyone can make a helper I can pass a collection to and specify an attribute I want to join with commas that would be great.
Here is my current code:
@itter = 0
for dpt in @ticket.departments do
if @itter > 0
@itter = 1
%> <%= dpt.name %><% end %>
I would ideally like to be able to do something like below, but any better way would be greatly appreciated.
list_collection(@ticket.departments, 'name', ',')