devroom.io/content/posts/2007-03-27-rails-tip-snippet-create-a-comma-seperate-list.md
2013-03-24 22:28:43 +01:00

19 lines
685 B
Markdown

---
title: "Rails Tip Snippet: Create a comma-seperate list"
kind: article
slug: rails-tip-snippet-create-a-comma-seperate-list
created_at: 2007-03-27
tags:
- General
- RubyOnRails
- Features
- TipSnippets
---
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:
<pre lang="ruby">@users.collect{|u| u.name}.join(', ')</pre>
Read more <a href="http://ariejan.net/tags/tipsnippets/">Tip Snippets</a>?