I discovered from here that if you have a script you want to run in the rails console, you sometimes have to copy paste it line by line (copy pasting it all at once doesn't always work)
This is very tedious for lengthy scripts
Is there a work around or faster way?
Example - this will not copy paste from text editor to console:
class Article
def initialize(title, link, paragraphs)
@title = title
@link = link
@paragraphs = paragraphs
end
attr_reader :title
attr_reader :link
attr_reader :paragraphs
end
Edit The above snipped does copy paste right into the rails console. But when I grab the same text from sublime text 3, it errors after the second line, with: Display all 522 possibilities? (y or n)..
The Answer I worked out why. My script (in sublime text) used tabs as indents. The rails console only accepts spaces as indents. That's an hour of my life I won't get back. I hope this saves someone else some time.
Press Ctrl + C twice in a row while Word, Excel, PowerPoint, or another Office app is open, and the Office Clipboard will keep the most recent 24 items you've copied.
Run source code from the editor in a console Open the required Ruby file in the editor (if necessary, select a fragment of code to be executed). From the main menu, choose Tools | Load file/selection into IRB/Rails console.
This issue (pasting multi-line code into irb on the console, on a Mac, using iTerm) bugged me for a long time and finally found the solution.
In my case the issue was with iTerm. It turns out iTerm by default pastes the content at a speed that is too fast for readline, the library that irb uses to read input.
The solution was to do Edit > Paste Special > Paste Slower, twice.
See here for a similar case: https://gitlab.com/gnachman/iterm2/issues/3607
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With