Stop outputting records when using rails console
Mar 26, 2021
TL:DR add begin … end && nil to your statement to stop it printing out all the values
I enjoy playing around in the rails console. Sometimes I load a lot of records. So for example
users = User.first(1000)
This then returns all user records to the screen which takes sooo looong to print out.
To stop this you can add
begin
users = User.first(1000)
end && nil
Now this will still store the records in users but it won’t print out the records to the screen as the return value is nil.
So obvious and yet until I asked colleagues today this has been a mild annoyance for years!