Inputting Terminal Commands When Running a Rails Server - ruby-on-rails

I just started using Rails a few days ago, and I'm having trouble with terminal commands. The textbook I am reading keeps telling me to run Terminal commands while having a Rails server running. This doesn't seem possible because the terminal just keeps outputting information about the server instead of prompting new commands, i.e. rake test. Is there a command I need to input to force the terminal to prompt my commands once I start the rails server?

Usually you will just start a second Terminal window or tab and run the commands your book mentions in there. It will use the same database, but not the same process your server is running in.

Related

Trouble starting Ruby console

I am fairly new to Ruby. I am have a problem getting my console to start a second time. I created my app (JacksApp) and created a model for it. I then shut down the app tried to restart the console a second time. When I type "rails c" I get this:
Running via Spring preloader in process 81129
Loading development environment (Rails 5.0.0.1)
No entry for terminal type "1.0.0/libexec:/Users/johnseabolt/.rbenv/shims:/Library/Frameworks/Python.framework/Versions/3.5/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin";
using dumb terminal settings.
irb(main):001:0>
I don't understand what's going on. Can someone help? I am in the directory for the app. I'm confused.
On MacOS Sierra, check TERM in Terminal.app
$ echo $TERM
xterm-256color
$ bin/spring stop
$ bin/rails c
No entry for terminal type "local/var/ry/rubies";
using dumb terminal settings.
irb> exit
$ bin/rails c
Cannot read termcap database;
using dumb terminal settings.
You can change TERM via Terminal > Preference > Profiles > Advanced > Terminfo > Declare terminal as: xterm.
Open new Terminal.
$ echo $TERM
xterm
$ bin/rails c
irb>
All sweet no warnings.
Now I leave it to someone with greater knowledge to explain why.
to fix this, you need to stop all rails processes and stop spring (bin/spring stop) and then make sure that you start up spring with an attached terminal.
There are basically three ways where spring would get started: bundle exec rails server, bundle exec rails console, or something like bundle exec guard or some other testing thing. If you start up rails through foreman, then it will run one of these commands, basically.
Starting the console will attach a input to the process, and this is where it will figure out the "terminal" type. Do that first, before everything thing else. Once that's loaded in memory, then its configured correctly, and starting up server or whatever will work find.
Server then console will give you the crazy error that you see. console then server will not.
Does it still let you use the console? The irb(main):001:0> at the end suggests that it is indeed working, you're just getting a warning about your terminal type setting being missing.
To fix the warning...If you're using a 3rd party terminal emulator, I'd reinstall that and see if that fixes it. Otherwise you can manually set your terminal type using export TERM=xxx in your ~/.bashrc file.

GIT Bash MingW32 Rails Console - Text input fails after exit and restart console

I installed Rails and I am having issues with the Rails console in Git Bash (MINGW32).
The first time I launch the Rails console using rails c, I can input text and everything works as expected. However if I exit the rails console using Ctrl-C then start the Rails console again, the text input is wrong.
In the example, I started the Rails console, input "Zombie.first", got the expected response, exited the console, started it again, entered "Zombie.first" again, but the console actually executes "Zoiefr". Any text I enter after this will be similarly affected until restarting git bash.
I performed the RailsInstaller install on two different Windows machines with the same result.
Does anybody have suggestions for how to fix it, or for other Windows development environments to try?

Ruby on Rails config change while server is running?

Hi I'm new to Ruby on Rails. I have installed the Testia Tarantula application and am trying to read up on Ruby.
My question is how do I start/stop the server.
For example: I want to change the Admin email, so I execute the following command to change the configuration of the app:
RAILS_ENV=production rake db:config:app
But is this command ok to execute while the server is running, it has 'db' in the command which is what would warn me that I shouldn't run it while the server is up. Anyone have some helpful tips for learning Ruby on Rails server app management?
Welcome to Rails!
You can run rake db:xxxxx while the server is running and it won't hurt anything. However I usually stop my server, run my rake command and then start it back up to ensure that all changes will be picked up. If running in production, I would think you may want to restart the server just to make sure. I believe that the schema is generated/updated upon server startup, just fyi.
As far as starting and stopping the server, if you are attached to it you can just use ctrl + c. If it is detached, you can search for the pid and then kill -9 .
Running rake db:anything will load rails on its own. It doesn't matter if you have a server up or not. This will happen in the background. Think of it as the same as running a sql script while the server is running. It's a separate process.

Could I run a Rails Server and type commands to my Rails Project through terminal at the same time?

I'm running my rails server through the terminal by typing rails server. After this, it seems the terminal is unavailable for further commands, but I would like to run some tests by typing rake test without having to CTRL + C out of my server, then rake test, and finally turning my server back on with rails server. Is there common solution for this?
I would also recommend using several tabs or even a terminal multiplexer such as tmux. However you could very well send the server process to the background with
rails s &
This will most likely clutter up your terminal with lots of log output unless you suppress the output as described here. You can foreground the process by typing
fg
and even look at the logs in a different terminal by typing something along the lines of
tail -f log/development.log
Depending on your terminal you can use File->new tab, or maj+ctrl+t to pen a new tab.
Personally i have one tab for the server, one for the tests using guard, one for the console and one to have an actual shell.

How can i type linux commands after using ruby script/server to set up a local server?

I am new to programming and ruby on rails. This question may be a little dumb.
After I set up a server(basically an empty one) in Ubuntu terminal using the "ruby script/server" command. My "usersname:~$" label is gone and the only way I know how to type in terminal again is to shutdown the server or Ctril + z. How do i keep the server running while I try to edit the contents of my server(such as writing controller)?
Use ruby script/server &. Adding & will run the server in bacground
Open another terminal ,
cd app_directory
and run any command you want. As a result your commands won't be affected due to page load

Resources