20

I have a Rails site that I'm developing on localhost Ubuntu and I have a mobile. My site is running on http://localhost:3000.

I want to access this directly via my mobile browser not going through the internet.

Is there any way to access it via WiFi or some other way?

Sajad Torkamani
  • 544
  • 1
  • 7
  • 18
millisami
  • 9,931
  • 15
  • 70
  • 112

8 Answers8

30

If your computer is accessible from internet, just enter in your mobile browser:

http://your.ip:3000/

You could also create a local network (via wifi for instance), connect to it with your cell phone and then do the same thing.

If you are using Rails 4.2+, start the server using:

 rails server -b 0.0.0.0 

(see http://edgeguides.rubyonrails.org/4_2_release_notes.html#default-host-for-rails-server).

notapatch
  • 6,569
  • 6
  • 41
  • 45
marcgg
  • 65,020
  • 52
  • 178
  • 231
22

1.) get your local ip by typing:

ifconfig |grep inet

into your shell/terminal. your ip usually looks like this: 192.xxx.xxx.xx

2.) then start the rails server with:

rails server -b 0.0.0.0

3.) your application can now be reached by typing:

192.xxx.xxx.xx:3000 into the browser.

Bergrebell
  • 4,263
  • 4
  • 40
  • 53
11

Using ngrok

So basically, you run the command

./ngrok http 3000

And you will see the output like that ngrok output

And all you need is copy the highlight URL and paste to the browser.

duykhoa
  • 2,227
  • 1
  • 25
  • 43
8

Execute

rails s -b IP_ADDRESS

Access mobile: IP_ADDRESS:3000

Rafael Schein
  • 81
  • 1
  • 1
3
  1. First find your Ip and note it down by typing ifconfig terminal(you should be connected to wifi or network)

ifconfig

than run the rails server by typing

rails server -b 0.0.0.0 (YOUR IP )

and press Enter SERVER WILL BE RUNNING ON YOUR_IP:3000 2. Now connect your mobile with the same network and open url

https://YOUR_IP:3000 CONGRATS YOU ARE RUNNING LOCALHOST ON MOBILE

3

On rails-server machine:

  • Make sure you're running rails-server.
  • Get your IP address, I got "192.168.1.112" for example.

On mobile:

Access through browser by using:

http://<your_ip_address>:3000

http://192.168.1.112:3000

NOTE: Your mobiles need to have the same network with rails-server machine.


To get yourself IP address, run this command in your rails-server machine.

MacOS or Linux Terminal:

ipconfig getifaddr en0 || ipconfig getifaddr en1
# => 192.168.1.112

Description:

  • ipconfig getifaddr en0 is for wifi connections
  • ipconfig getifaddr en1 is for wired connections

Windows:

ipconfig

Then looking for IPv4 Address.


Running rails-server

On rails-server machine, it's okay to regularly run:

bin/rails s

If you found issue, you can try the following:

bin/rails s -b 0.0.0.0

Note: 0.0.0.0 is not an IP address, it's a shortcut for the system binding call to use all available IP addresses including 127.0.0.1, localhost.

Access through http://localhost:3000/

Martin K.
  • 1,168
  • 15
  • 16
1

if you get ipconfig command not found on ubuntu Try: ip route to get the IP address then you can run rails server as explained in other answers.

rails s -p 3000 -b 192.168.0.102 (Replace IP with your system's IP).

Now you should be able to access on you mobile browser by just entering http://192.168.0.102:3000/

Imran Ahmad
  • 2,798
  • 3
  • 28
  • 49
0
  • run your server on 0.0.0.0:port_no rather then 127.0.0.1 or localhost

  • then check your IP address by typing a command in your terminal

    ipconfig enter image description here

    here you can check your host machine's IP address.

-Now we have to enable 3000 in your case port to be accessible in the network

write following commands

sudo ufw enable
sudo ufw enable port_no
sudo ufw status

then you will be able to see your port is enabled

-Now you can access your server in any device browser using IP address:port_no

enter image description here

Check out this picture where I am accessing Django Web App running locally on Ubuntu and I am able to access it on my windows laptop which is in the same network via ip_addess:port_no which in my case is 8000

You can access the same website at

justnajm
  • 4,422
  • 6
  • 36
  • 56
arpansahu
  • 41
  • 1
  • 4