Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 652
Autodidact Avatar asked Jan 07 '10 11:01

Autodidact


People also ask

How do I access localhost from another device?

Jump to step:Connect both devices to the same network. Find the IP address of your computer. Find the host name of your computer. Open your mobile browser and visit the IP address or host name.

How do I start rails app locally?

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 .

How do you access a website running on localhost from iPhone browser?

Accessing localhost from the iPhone will simply do a loopback / try to connect to itself (If it supports that?). What you need to do is find the IP of your desktop machine (e.g. If Windows, go to the Command Prompt and type ipconfig or go to Network and Sharing Centre and look up connection status .


2 Answers

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).

like image 158
marcgg Avatar answered Oct 21 '22 11:10

marcgg


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.

like image 39
Peter Piper Avatar answered Oct 21 '22 13:10

Peter Piper