Line break when using rails console (Terminal)

When I print large ActiveRecord requests, before the request completes, the line breaks and I cannot even read or enter the command correctly. Am I using ubuntu.Any solution?

+6
source share
4 answers

Finally, the problem of changing the size of the terminal narrowed. I usually maximize the terminal to enter large commands, hence the problem. It turned out that this can be solved by processing the SIGWINCH signal to resize the IRB. In the solution below, I also resize the Hirb.

Add the following lines to ~ / .irbrc (create one if it does not exist):

Signal.trap('SIGWINCH', proc { y, x = `stty size`.split.map(&:to_i); Hirb::View.resize(x, y) if defined? Hirb } ) 
+7
source

A more general way is to use \ at the end of your line.

Using the same Kenny Grant example

 ruby> User.very.long.chain.of.arel.commands. \ where('thing = ?', 4).very.long.chain.of.arel.commands 

the last line should not end \ , and then the entire command will be executed.

+3
source

I noticed the same error with irb, rails console uses irb by default. That's why I use pry, look here how to configure pry with rails.

+1
source

If your request looks like this:

 rails c ruby> User.very.long.chain.of.arel.commands.where('thing = ?',4).very.long.chain.of.arel.commands 

You should be able to do this:

 ruby> User.very.long.chain.of.arel.commands.where('thing = ?', 4).very.long.chain.of.arel.commands 

and divide it into any commas in the conditions, then when you hit return at the end, it will execute.

0
source

Source: https://habr.com/ru/post/923631/


All Articles