开发者

Command output in rails console: Explanation of unwanted output?

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?


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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜