gespinha
gespinha

Reputation: 8487

How do I print an object property in the rails console?

I am using the rails console and I'm trying to loop through an array of objects, and print just one of their properties, say for example, the name property.

How do I do this?

Upvotes: 0

Views: 734

Answers (2)

Sunil Kumar B G
Sunil Kumar B G

Reputation: 26

you can use pluck method for fetching attributes.

Model.pluck(:name)

Upvotes: 1

kjmagic13
kjmagic13

Reputation: 1318

You want something like this:

Model.all.map(&:name)

Upvotes: 1

Related Questions