Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails server not working?

I'm following the first Ruby on Rails 3 tutorial from PeepCode and at around 27-29 minutes in, they have us start the Rails server. To the best of my knowledge, I have Rails (and Ruby) successfully installed.

When I run the command rails server (from Windows 7 Command Prompt per the instructions of the video), I get the message:

=> Booting WEBrick
=> Rails 3.1.3 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
[2011-12-02 18:37:57] INFO WEBrick 1.3.1
[2011-12-02 18:37:57] INFO ruby 1.9.3 (2011-10-30) [i386-mingw32]
[2011-12-02 18:37:57] INFO WEBrick::HTTPServer#start: pid=5584 port=3000

And it doesn't return to the prompt, indicating that it is running. Also, to me (and compared to the video), this looks like a successful message.

However, when I browse to the URL, http://0.0.0.0:3000, as directed by the video, I get an error (while the video opens to the default index page for Ruby). The error I get is:

Error 108 (net::ERR_ADDRESS_INVALID): Unknown error.

Since I'm using Google Chrome, it also says:

The webpage at http://0.0.0.0:3000/ might be temporarily down or it may have moved permanently to a new web address.

So, I was wondering how to fix this?

like image 556
Bhaxy Avatar asked Dec 03 '11 02:12

Bhaxy


People also ask

How do I enable Rails server?

Go to your browser and open http://localhost:3000, you will see a basic Rails app running. You can also use the alias "s" to start the server: bin/rails s . The server can be run on a different port using the -p option. The default development environment can be changed using -e .

Which server is used by Rails?

The Ruby standard library comes with a default web server named WEBrick. As this library is installed on every machine that has Ruby, most frameworks such as Rails and Rack use WEBrick as a default development web server.

How do you stop Rails server forcefully?

For Rails 5.0 and above, you can use this command Use ctrl+c to shutdown your Webrick Server.


2 Answers

0.0.0.0 is the ip address that Webrick is binding to. It means 'listen on all interfaces'. In other words, you can connect to this application from the internal address (localhost or 127.0.0.1) as well as the external address on the network (192.168.1.x or 10.0.10.x or a domain name that resolves to an address this machine has on the network). The server doesn't care where the request comes from.

If, however, you started rails server with the '-b' or '--binding' option and told the server to bind to 127.0.0.1, the server would not respond to requests to the external interface. You could still use 127.0.0.1 or localhost but you could not connect to this server using it's external ip address locally or from another machine.

Going to http:// 0.0.0.0:3000 works on my Linux system and most likely the screencast you were watching was using a mac which would also work. My guess is that 0.0.0.0 isn't supported on Windows.

Just use localhost if you are on the box or the ip address of the box if you are accessing it from another machine. That is what I do, even when I'm running a machine that understands 0.0.0.0.

like image 63
Matt Hulse Avatar answered Oct 19 '22 04:10

Matt Hulse


You can start the server with this command:

rails server -b localhost

But as a lazy typist, in my .bash_aliases, I have this alias

alias rs='r s -b localhost'

With the alias, I can start the server with just:

rs
like image 32
Marek Příhoda Avatar answered Oct 19 '22 02:10

Marek Příhoda