How to connect to a localhost Rails site via mobile device locally?

Viewed 17482

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?

8 Answers

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/

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/

  • 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

Related