Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Line breaks when using rails console(Terminal)

When I type large ActiveRecord queries,Before finishing the query, the line is breaking and I can't even reading or typing the command properly.I am using ubuntu.Any solution?

like image 329
shajin Avatar asked Aug 24 '12 07:08

shajin


3 Answers

Finally narrowed the issue to be with resizing the terminal.Usually I maximize the terminal for typing large commands , hence the problem. Found out that this can be solved by handling the SIGWINCH signal to resize IRB.In the solution below i am also resizing Hirb.

Add the following lines to ~/.irbrc (create one if it doesn't exist) :

Signal.trap('SIGWINCH', proc { y, x = `stty size`.split.map(&:to_i); Hirb::View.resize(x, y) if defined? Hirb } )
like image 157
shajin Avatar answered Nov 19 '22 08:11

shajin


A more generic way is using a \ at the end of your line.

Using the same example of "Kenny Grant"

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

the last line should not have any ending \ and then the whole command will be executed.

like image 28
Samiron Avatar answered Nov 19 '22 08:11

Samiron


I've noticed the same bug with irb, rails console uses irb by default. That's why I'm using pry, look here how to setup pry with rails.

like image 1
megas Avatar answered Nov 19 '22 06:11

megas