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?
Asked
Active
Viewed 2,982 times
4 Answers
8
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 } )

shajin
- 3,214
- 5
- 38
- 53
-
For those not using Hirb `Signal.trap('SIGWINCH', proc { y, x = `stty size`.split.map(&:to_i); Readline.set_screen_size(y, x) if defined? Readline } )` – Urkle Aug 10 '16 at 13:11
3
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.

Samiron
- 5,169
- 2
- 28
- 55
0
If your query is 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 split it on any commas within the conditions, then when you press return at the end it will execute.

Kenny Grant
- 9,360
- 2
- 33
- 47