I was going through the AR query interface guide and from it I got the impression that the Rails console should be interpreting the \n in the output from the .explain command as a newline, rather than printing it as raw text on the screen. Reading a query on one single line is inconvenient to say the least.
I can “fix” the formatting issue by prepending “print” to any ActiveRecord::Relation object output to the console, as in the canonical example:
print User.joins(:posts).explain
Is it supposed to work that way by default, or am I doing something wrong? Do people always stick to prepending print?
Thanks!
Yes, the rails console displays the
\ncharacters (rather than rendering) them by default. I always addprintexactly as you have done.