devroom.io/content/posts/2007-03-27-rails-tip-snippet-create-a-comma-seperate-list.md
2019-06-05 14:32:16 +02:00

731 B

+++ date = "2007-03-27" title = "Rails Tip Snippet: Create a comma-seperate list" tags = ["General", "RubyOnRails", "Features", "TipSnippets"] slug = "rails-tip-snippet-create-a-comma-seperate-list" description = "Got an array? This is how you get a CSV!" +++

Do you have the need to create a list of roles a certain user belongs to? Enumerate the users attached to a company? All you want is a simple list with the names seperated by commas.

Users: John, Dick, Harry

With Ruby on Rails this is really easy. You probably have a collection of user objects. All you want is a list of names:

@users.collect{|u| u.name}.join(', ')

Read more Tip Snippets?