Rails Tip Snippet: Create a comma-seperate list
source link: https://www.devroom.io/2007/03/27/rails-tip-snippet-create-a-comma-seperate-list/?utm_campaign=Feed%3A+ariejan+%28ariejan%7Cdevroom.io%29
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Rails Tip Snippet: Create a comma-seperate list
Posted:
2007-03-27
- Last updated:
2019-06-05
Tagged 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:
@users.collect{|u| u.name}.join(', ')
Read more Tip Snippets?
My site is free of ads and trackers. I record privacy-respecting usage statistics with Fathom.
Was this post helpful to you? Why not ☕ Buy me a coffee
Copyright © 1999-2020 Ariejan de Vroom <[email protected]>
Live now; make now always the most precious time. Now will never come again.
– Jean-Luc Picard
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK