68

I am setting up a RoR development environment on a Windows machine. I was wondering how I can set it up so a few friends of mine can have access to the web server and monitor the progress?

It would only be 2 or 3 people connecting at anytime time max.

Yu Hao
  • 119,891
  • 44
  • 235
  • 294
Dan
  • 2,299
  • 2
  • 20
  • 41
  • 1
    Not programming related - more webmasters or superuser or sysadmin – KevinDTimm Feb 14 '12 at 19:09
  • 5
    It would be better and probably easier to set up a free [heroku](http://www.heroku.com) app and do a _git push heroku master_ when you are ready to show something. Allowing people to view your dev is usually counter-productive. – David Nehme Feb 14 '12 at 19:11

5 Answers5

213

The simplest way requires NO additional installations: just add a single option to your rails server (or rails s) command when you start up the server:

rails s --binding=0.0.0.0

The 0.0.0.0 address means "listen to requests from anywhere." On many systems, the default is 127.0.0.1, which means "listen to requests from localhost only."

(If you don't also specify a -p or --port option, then the port shall be 3000, as usual.)

JellicleCat
  • 28,480
  • 24
  • 109
  • 162
  • 23
    this is the best answer – jacob bullock May 07 '15 at 18:29
  • On machine 'A' I run `rails s --binding=0.0.0.0` ... how do I connect with machine 'B' on the same wifi? – slindsey3000 Jul 20 '15 at 19:54
  • 5
    @slindsey3000, on machine B, use the IP address of machine A as the hostname in your URL. If you're on linux run `sudo ifconfig` on machine A to learn its local IP address; if you're on Windows run `ipconfig`. The local IP address will probably begin `192.168.X.X` or `10.71.X.X`. So your address bar in machine B would be something like `http://192.168.0.14:3000/` – JellicleCat Jul 20 '15 at 21:30
  • even though this is working, binding to 0.0.0.0 is considered insecure and I would always use the IP address. But still a valid answer – awenkhh Aug 21 '15 at 09:59
  • Simple and straight to the point. This answer saved me from hours of research, Thanks :) – Kebab Programmer Apr 30 '16 at 12:52
  • ty, I forgot I needed this trick for to get charles vs. local rails – aschyiel Jun 16 '16 at 18:28
  • 2
    If you go this route, you may need to configure your firewall and or router to allow external access – Josh Oct 09 '16 at 19:16
  • Im late to the party. But this should be the accepted answer. – prufrock Jul 30 '21 at 18:58
27

You can tell your development server to listen on your publicly accessible interface:

If you're running a server via rails server, you can specify the IP to listen on via -b <ip> or --binding=<ip>. By default, the server listens on 0.0.0.0, that is, only for local connections.

Usage: rails server [mongrel, thin, etc] [options]
    -p, --port=port                  Runs Rails on the specified port.
                                     Default: 3000
    -b, --binding=ip                 Binds Rails to the specified ip.
                                     Default: 0.0.0.0

You can instead find out what your machine's network address is and bind to that address instead, but you will have to forward ports and figure out what your publicly routable IP address is on the Internet; this is outside the bounds of Stack Overflow.

user229044
  • 232,980
  • 40
  • 330
  • 338
  • 10
    0.0.0.0 is actually all connections on the machine, so you don't need to bind to a specific IP address. I connect to my dev apps on 0.0.0.0 all the time from my phone to check mobile layouts. Likely a hole in the firewall is all that is needed. – Eric Feb 14 '12 at 19:29
  • @Eric Could you just explain me what address do you put on your phone when your local rails server is running on 0.0.0.0 ? Will it be https://0.0.0.0:3000 or your ip of the computer where the server is running for example: 192.168.0.100 ? – Aleks Dec 19 '13 at 11:18
  • 1
    I have found it :) you run a local rails server like this `rails s -b 192.168.0.100` and then on your phone you set up address to target it to 'http://192.168.0.100:3000' , or whatever your port is assigned to when it is run. Great – Aleks Dec 19 '13 at 11:28
  • A lot of networks don't let this happen for some reason – Adam Waite Jun 26 '14 at 10:54
22

Give localtunnel a go. It's a ruby gem so you shouldn't have any problem getting it going:

gem install localtunnel
localtunnel 3000

The first time you do that it'll ask you for an ssh key, but once you've got that set it'll show you the public url that you can share. Anything running on the specified port will get exposed at that url.

Showoff-io looks like a similar service, but I haven't used it so I can't comment. Also, it's paid and requires signup.

MhdSyrwan
  • 1,613
  • 3
  • 19
  • 26
David Underwood
  • 4,908
  • 1
  • 19
  • 25
7

As someone suggested, use ngrok.

It's stupidly easy.

Sebastialonso
  • 1,437
  • 18
  • 34
2

Allow remote connections by binding the Rails server to 0.0.0.0.

Here's the short notation for those who don't like typing :

bin/rails s -b 0.0.0.0

If you also want to allow IPv6 connections (Puma):

bin/rails s -b [::]
Yvo
  • 18,681
  • 11
  • 71
  • 90