Skip to main content

Rails Tip Snippet: Create a comma-seperate list

·71 words·1 min· ·
General RubyOnRails Features TipSnippets
Ariejan de Vroom
Author
Ariejan de Vroom
Jack of all Trades, Professional Software Craftsman

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?

Related

Rails Tip Snippet: Logging informational messages to your log
·124 words·1 min
General RubyOnRails Features TipSnippets
New in Rails: Resource Scaffold Generator
·214 words·2 mins
General RubyOnRails Features
“Print this page” with Ruby on Rails
·302 words·2 mins
General Everything RubyOnRails Features