Runy-on-rails – the command output in the Rails console: No description of the output?

I am using rails console and some models. I am running something:

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

This is fine, it allows me to see all the values ​​of a specific column, but after printing out these lines, it prints out the entire model.

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

The console always prints the return value of the command. The return value of .each is the initial array. < p>

So you either return the value you need:

Model.find(:all).map{ |x| x.name }< /pre> 

Or prevent the output and return something like nil:

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

I am using rails console and some models. I am running something:

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

This is fine, it allows me to see all the values ​​of a specific column, but after printing out these lines, it prints Out the entire model.

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

The console always prints the return value of the command. And the return value of .each is the initial array.

So you either Return the value you need:

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

Or prevent the output, return something like nil stuff:

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

< /p>

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 3303 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.