views:

33

answers:

1

I am working with the rails console, and some models. I am running things like:

Model.find(:all).each do |x| p x.name end

which is nice, this lets me see all the values of a specific column, but after it prints those lines, it prints out the whole model.

Why does it do this? How can I stop it?

+3  A: 

Console always prints the return value of the command. And the return value for .each is the initial array.

So you either return the value you need:

Model.find(:all).map{ |x| x.name }

Or prevent output, returning something like nil:

Model.find(:all).each{ |x| p x.name }; nil
Voyta