How do I get two instances of "Command Prompt with Ruby" - ruby-on-rails

I am an absolute beginner with Ruby on Rails and I seem to have a problem with the way I should be doing things.
If I use "rails server" in order to be able to test my application, I can't do anything else in the command line.
Is there another way of doing scaffolding, other than command line? If not, how to I get two "Command prompts with Ruby" at the same time?

When you search for it from your metro screen, right click on it and then click on Open in a new window.

Open a new terminal tab before you start your Rails server, and then you can just leave it running in the background. However, do make sure you go back to that tab and specifically shut the server down before closing terminal as it doesn't always automatically shut down when terminal is closed and then you may have problems when reopening later.

Related

Command line won't let me type, in the midst of a Rails Console session

In Rails console I entered an Active Record query, and it took up more than the whole screen, so it was scrolling. I forgot to hit q to get out of it and instead hit Ctrl-C. I got some errors, then I got some of the Rails console output, then I hit ^C again, then my prompt came up...
But I can't type anything. Well, actually I can type, but I can't see anything.
If I type exit it will exit the Rails console and get me back to my prompt, and then if I type rails c I'll get back to my console. Except none of the things I just mentioned typing appear on the screen when I type them.
And once I'm back inside the console I still can't see what I'm typing. I have to open a new terminal.
I've had this happen in a number of different scenarios, probably all where my reflexes exited a process the wrong way (like with ^C instead of q), and this is just the first one where I could pin it down.
Does anyone know how to fix this without having to scrap my work and open a new terminal?
Something you've typed, or something output from your query in console, has disabled or redirected the "echo" setting in your shell - so, you're still able to type commands, but you just can't see them. If the Active Record query returned binary data, it's quite likely that some bytes of the binary data happened to be an escape code that changed your echo setting. It's also important to realize that if your echo setting changed, it's quite possible that other settings have changed as well.
If you're at your shell prompt, you would just type the unix command reset to restore normal settings. However, if you're still in your Rails console, you'll need to type:
system 'reset'
to run that command from Ruby.
Type reset and press enter, it should be fixed.

Terminal cursor disappears when using Rails server and pry/byebug together

If I trigger pry or byebug, eventually while using the live-debug mode the cursor will disappear, and input will become slow/laggy. Ultimately I have to Ctrl-C and kill the unicorn/puma process. After I've quit the process the terminal works, but the cursor is sometimes still missing/invisible. Then I have to close the terminal and open another. I've tried two different servers (puma/unicorn) and two different debugging tools (pry and byebug).
Hard to say if this is related to the debug tool, the rails server or my Terminal. I'm using Terminal.app with Solarized theme.
When the cursor disappears you can enter the command stty echo and hit enter. That should bring the cursor back.

How to use same terminal window after using "rails server" command?

Okay here's my problem.
I type in "rails s" and then my terminal won't let me type in any commands. So I have to start a new terminal window, which is pretty annoying.
On the other hand I can type in "rails s -d" which detaches, and then it's a pain to stop the server when I need to. (Instead of using control+c, I have to find the PID and use kill -9 PID)
I'm not a professional, so if anyone has any advice it would be much appreciated, thank you!
I don't believe there is a way to do the thing you are specifically asking for.
However, I use Iterm2 which allows me to open multiple terminal windows in one window, either by splitting my iTerm2 window or by creating multiple tabs. That way I can just make the terminals that are holding rails server and my development.log tail very small unless something interesting happens in them.
I use screen, you can also use TMUX but they are window managers in terminal and you can create multiple windows in same terminal window :)
Read up on them at WikiVS as that might help you :)
http://www.wikivs.com/wiki/Screen_vs_tmux
Screen: http://www.gnu.org/software/screen/
TMUX: http://tmux.sourceforge.net/
So you can easily switch and maintain same terminal window. You can't obviously use the EXACT same window that rails server running but it's close enough without having to do the searching for the PID.
You can type: rails s &. I'm not sure if this is what you meant.

Command Prompt input

I have a Windows 7 laptop, and I think I installed everything correctly, and I am trying to follow a couple tutorials to learn from. I can make a new application ok, and I can start the server just fine by typing "rails server", and I can go to the localhost:3000 'welcome aboard' page just fine, but after that the tutorials ask me to type other stuff into the command prompt window. The problem is, with the server running, I can't type anything into the command prompt window! I'm obviously doing something wrong.. anyone have any idea of what I should be doing?
The easiest way is to open another command window.
I set up students to use more than one command window like this:
one for typing most commands
one for running the server
one for printing the log file using the "tail -f" command to show ongoing progress
one for running rails console

Unpause a rails server that was paused in a different terminal window

I'm on mac osx using zsh. If I start a rails server with "rails s" I can put it in the background by hitting "ctrl-z" in my terminal (zsh).
If I open up a different terminal window then I don't see the rails server if I do "jobs". However, I can see it when I do "ps".
Is there a way I can somehow "unpause" the rails server in this new terminal window?
You can not easily move a process to a new tty. The easiest solution would be to start it in a screen session, detach screen and then resume in the new terminal.
The job is "stopped" by sending it a SIGSTOP.Your C-z doesn't send the job into the background. It "stops" it. You can then move it into the background using the bg shell builtin. However, if you send this process a SIGCONT (kill -CONT <pid>), it should bring the process back to the foreground. This can be done from a different shell.
You will not see it if you type jobs because it is a job controlled by a different shell (the other terminal window and not the one where you typed jobs). Processes however are "global" and can be seen from anywhere using the ps command (as you rightly pointed out).
Update: Looks like I spoke too soon. Apparently, the signal alone isn't enough to bring it back to the foreground. Probably something to do with the shell.

Resources