Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3430752
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T07:14:33+00:00 2026-05-18T07:14:33+00:00

No matter what language I’m using I always need to display a list of

  • 0

No matter what language I’m using I always need to display a list of strings separated by some delimiter.

Let’s say, I have a collection of products and need to display its names separated by ', '.
So I have a collection of Products, where each one has a ‘name’ attribute. I’m looking for some Rails method/helper (if it doesn’t exist, maybe you can give me ideas to build it in a rails way) that will receive a collection, an attribute/method that will be called on each collection item and a string for the separator.

But I want something that does not include the separator at the end, because I will end with “Notebook, Computer, Keyboard, Mouse, ” that 2 last characters should not be there.

Ex:

concat_ws(@products, :title, ", ")
#displays: Notebook, Computer, Keyboard, Mouse

Supposing @products has 4 products with that names of course.

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T07:14:33+00:00Added an answer on May 18, 2026 at 7:14 am

    you should try the helper to_sentence.

    If you have an array, you can do something like

    array.to_sentence. If your array has the data banana, apple, chocolate it will become:
    banana, apple and chocolate.

    So now if you have your AR Model with a field named, you could do something like

    MyModel.all.map { |r| r.name }.to_sentence
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let say that I have a website with some information that could be access
I need a simple parser generator. The language does not matter. It only has
I need a programming book with questions and answers, doesn't matter what programming language
If I have a program in C++/C that (language doesn't matter much, just needed
I have a member website, doesn't matter what language or framework as it is
We are using ARM200 to learn assembly language. I have a portion of memory
My primary language is PHP, but I have done some (not very much) programming
It does not matter what programming language. Can anyone please give me an idea
Or any other normal scripting language for that matter. I know there is VBScript
Ok I am coming into a stumbling block no matter what language I am

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.