Trouble starting Ruby console - ruby-on-rails

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.

Related

Failing to open rails console and run a script

I'm trying to open a Rails console and run a ruby script in it. The script works fine till the rails console opens and then nothing happens. Only when I exit the console manually, do I get an error message saying:
-bash: load: command not found
These are the commands I'm using:
source /etc/profile
source /etc/default/<my-app>
cd /usr/share/<my-app>
NO_AUTH=Y bundle exec ruby-flo -S rails console
load '/home/sirish.aditya/test_code.rb'
How do I load the script into the console?
You could use this
echo "$(ruby /home/sirish.aditya/test_code.rb)"
As per you requirement, you could even try rails runner or whenever gem.
It doesn't work like that. As soon as the rails console is invoked either manually or through a bash script, you are essentially running a separate process which has no visibility into the subsequent statements (ex: load).
When you quit the rails console then the process of execution comes back to the main process (which is bash) which does not have any idea what load means and is failing.
You should either use rails runner or custom rake task for what you want to achieve.
This is working:
cd /usr/share/<my-app>; source /etc/default/<my-app>;
cat ~/test_code.rb | NO_AUTH=Y bundle exec ruby-flo -S rails console

How to debug `rails s` when it hangs?

I have strange problem. After running rails s on some project, the script hangs with no output and no logs. How can I debug it and inspect what's going on? I use rvm with ruby 1.9.2.
check log/production.log to find the last file or line of code executed and try to figure out what went wrong.
If you want to dig a big deeper, you can use utilities such as "strace" or "dtruss" to see what files are being opened.
Linux:
$ strace rails s
Mac:
$ sudo dtruss rails s
You might not know what all of the output means, but you might get an idea if something is missing.

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

Inputting Terminal Commands When Running a Rails Server

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.

Resources