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 6159819
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T21:11:44+00:00 2026-05-23T21:11:44+00:00

Sorry for this simple question but I am stuck here. I am trying to

  • 0

Sorry for this simple question but I am stuck here.

I am trying to create a helper method that simply prints for each object the attribute “name” of my Table “Term”.

I tried this:

def display_name(terms)
  terms.each do |term|
    p term.name
  end
end

But instead of printing each objects name, it prints an array for each object with all attributes.

As an example:

[#<Term id: 1, name: "test", definition: "first definition", created_at: "2011-07-21 14:52:12", updated_at: "2011-07-21 14:52:12">, 
 #<Term id: 2, name: "second test", definition: "blabla", created_at: "2011-07-20 18:00:42", updated_at: "2011-07-20 18:04:15">

I am trying to find what I can do with the documentation (content_tag, concat, collect) but it doesn’t seem to provide the result I want..

Thanks for your explanation

  • 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-23T21:11:44+00:00Added an answer on May 23, 2026 at 9:11 pm

    The reason for this is because it does not actually print the name, it returns the value from terms.each since that was the last statement in the method.

    I would probably use the map method to collect all the names into an array first and if you want a String instead of an Array then I would join them with whatever separator that is preferred, like this:

    def display_name(terms)
      terms.map(&:name).join ", "
    end
    

    You could also add a parameter to choose the separator if you like. Like this:

    def display_name(terms, sep = ", ")
      terms.map(&:name).join sep
    end
    
    # in view
    display_name(collection, "<br/>")
    

    By default it then uses a comma to separate them but you can manually choose something else.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Sorry to bother you with such a simple question, but I'm stuck here since
Sorry if this is a dead simple question but I'm confused from the documentation
Sorry for this simple question, but i'm missing the forest through the trees. These
Hello I am sorry to bother you with such a simple question but this
sorry if this is a simple question but i am new to java and
Note: I'm sorry if this is an extremely simple question but I'm somewhat obsessive
Sorry, simple question but it is something that is always confused me when speaking
I am sorry if this is a really simple question but I am really
Hey guys, sorry for this probably fairly simple question but I'm starting to get
Sorry for this question but I am stuck. I have folowing syntax: class xx

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.