devroom.io/content/posts/2007/2007-03-27-rails-tip-snippet-create-a-comma-seperate-list.md

21 lines
720 B
Markdown
Raw Normal View History

2015-03-26 11:28:08 +00:00
+++
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"
2017-09-11 12:20:15 +00:00
description = "Got an array? This is how you get a CSV!"
2015-03-26 11:28:08 +00:00
+++
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:
2017-09-11 12:20:15 +00:00
2024-01-30 08:26:51 +00:00
```ruby
@users.collect{|u| u.name}.join(', ')
```
2017-09-11 12:20:15 +00:00
2015-03-26 11:28:08 +00:00
Read more <a href="http://ariejan.net/tags/tipsnippets/">Tip Snippets</a>?