why I am not able to access rails localhost on my mobile or other computer - ruby-on-rails

I am trying to access my localhost of rails running project on my mobile device.
This is how I am trying.
http://ip:3000
But it says the webpage is not available.
I tried with another port as well and It doesn't work even there?
What's wrong here? I use to check earlier this way.
Please guide

Try running this code below to your server:
rails s -b 0.0.0.0
This worked for me!

Just give:
ip = your phone's ip address
(Check it in connection information if you are running this on Ubuntu)
ip:3000/your_page if you do not have mapped your root to some page.
Else ip:3000 will work if you have mapped root to some page.
Try it in Chrome and see as it doesn't need any http or https it automatically selects the required one.

Here is how I did it
Put both your computer and phone on the same wifi network
rails s -b 0.0.0.0
routerlogin.net (or however you access your router it will say on the back of router)
get attached devices to the router. Note your computers ip. Mine was 10.0.0.20
on phone go to 10.0.0.20:3000 (but use the ip for your computer from step 4)

Related

I cant access my server rails app

Well as the title says i cant access my ruby on rails app, on the server i run the command:
rails s
After that everything works like it is suppose to work but it doesn't
When I enter my ip on my browser i put it like this x.x.x.x:3000 I have also tried x.x.x.x:3000/andtheurls
On my server i have run the command:
nmap localhost
To see if the port 3000 is opened, and it is.
My browser just tells me that it cant access the site and that my conexion has been rejected
I use and ubuntu 14.04 for my server
Not sure what IP address you're trying to use, but the easiest way is just to type localhost:3000 in your url bar.
By the way, this is the same as 127.0.0.1:3000. You should realize that this isn't your actual public IP address, though. Everyone's local IP address is 127.0.0.1: it is the loopback's interface address.

Accessing Ruby on Rails app from a Remote PC/Network - Windows 7 WEBrick

I am making an app using Rails on my home pc, and need to access the page from a computer at work.
I've found a few questions relating to this, but nothing like a process which I can follow as someone who doesn't have an awful lot of networking experience.
I know I need to open the port which I am using, but I can't seem to do this, as in windows firewall/allow programs I cant see the 'add port' button...
Am I right in thinking that the server should be set up to use default gateway as the IP ($bin/ rails server -p 192.168.0.1), and then use my public IP to access it from my work PC?
Any help/guidance is much appreciated!
Follow one of the port forwarding tutorials which are easily found online.
The IP you set up which looks like 192.168.0.12 or similar is the local IP address. Use this too access the website on the home network: 192.168.0.12:3000 if you forwarded port 3000.
$/bin/ rails s -b 192.168.0.12 -p 3000
Now, to access the server from external network, navigate to: http://your.public.ip.address:3000, which can be found by searching "what is my ip address" in Google.
There are some projects/software that help the job easier:
https://ngrok.com
http://localtunnel.me
http://proxylocal.com

Error when testing app from mobile device - ERR_CONNECTION_REFUSED

After upgrading to OSX Yosemite, I can no longer test my app on a mobile device by using my development machine's (MacBook Pro) IP address. For example, I used to be able to view a Rails app on a phone by going to http://192.168.0.4:3000, but now I get the following error:
ERR_CONNECTION_REFUSED
I get the same error when testing an AngularJS app using the grunt server running at http://192.168.0.4:9000
Any help will be greatly appreciated.
It could help to bind the server to your local IP, like
rails s -p9000 -b192.168.0.4
to start your rails app
Consider giving a try to Pow. Its pretty simple to install, and a great solution to share a local development across multiple devices.
Like it explains in their homepage, you can install it with just :
curl get.pow.cx | sh. To prevent any errors, install in Terminal app outside a Tmux session.
And just symlink your app :
cd ~/.pow
ln -s /path/to/myapp
You can access your app at http://myapp.dev/, and at http://myapp.[your ip address].xip.io from another device.
Not a direct response to your issue, but an alternative to setting yourself a configuration in your preferences.
Turn IPv6 off. It Prevented me from connecting to my localhost from other computers on my LAN. And, with the newer versions of OSX there is no way to turn it off in the Network Preferences Panel so you have to do it from terminal.
Open Terminal and enter to turn it off:
networksetup -setv6off Wi-Fi
And this to turn it back on:
networksetup -setv6LinkLocal Wi-Fi
If you are connected via Ethernet or something else just run this command to list the available options:
networksetup -listallnetworkservices
and replace "Wi-Fi" with the appropriate device.
I don't have a mac, but that seems to be the server not accepting connections, if that is the case, it's only accepting localhost connections, try binding de server to accept all connections or bind it to 0.0.0.0 ip
Can you access that IP from Browser? are you sure your IP is in the same range with 192.168.0.4? It is your mobile device connected on the same network? Maybe you used internet sharing before update to Yosemite and now is off?
I think your IP address changed. Telnet from console(terminal) your I.P. port. If 192.168.0.4 is your real Ip then maybe add(as root or via sudo) an entry in /etc/host file an entry as 127.0.0.1 192.168.0.4. Restart network or reboot. Also you can try nmap ( on ip to see open ports). Nmap has been ported to OSX just google for installer.

How do you host a Ruby on Rails application on a local network, so multiple people can access it?

I'm brand new to RoR and have pretty much 0 experience with it. I have been handed down somebody else's project and I need to find a way to host the application, so people can just access it locally. The application is a spider script/walker script/web scraper whatever you call it. Basically it connects to a website, logs in, retrieves certain data each day and maps it with the previous data. While on the local machine, you use it, go to localhost:3000, and you get the webpage the previous person designed. I was just wondering how I could get that page to be public for the people on our local network, so they could connect to some arbitrary IP and see the same page (it updates daily)?
What I tried doing is making the folder containing the application public to the network, but in order to use it, I would have to make everybody on the network allowed to write to it and each person would have to install RoR to use it. I want to avoid that since it doesn't seem logical, nor is it what I'm trying to do.
Looking at the code, I can reverse engineer and understand what it does, but when it comes to hosting web apps locally or something of that sort, I have never done this before. Please help!
Thanks in advance!
**EDIT
-This is all being done on a Windows 7 machine.
Since you're on Windows, open up a command line and run ipconfig to find out your local IP. It will be listed under 'IP Address'.
Tell people in your LAN to access http://192.168.x.x:3000 replacing 192.168.x.x by your IP address from step 1.
EDIT: One major thing that I missed, you are windows. On windows u could use thin and put it behind a load balancer. Although i would suggest hosting it on a UNIX machine :)
Although Running it in webrick(webrick is the application server for development i.e when u run rails s) will let other users access the website NEVER do the same for a production application. If you want to run this application in production, u need more powerful application servers like passenger. I would suggest you use it with Apache or Nginx instead of stand alone passenger. Once all this is setup others can use your application by entering the IP(xx.xx.xx.xx) also u can ask your system admin to setup a local DNS so your users need not remember the IP address always.
Description:
While starting Rails Server, we can also setup some options to configure the IP address and also the port number of the site under development environment to host the website in local network. So if we want to change the IP from http://127.0.0.1:3000 to http://192.168.x.x:port (x= 0 to 255 any one number), we can set that in Rails server command! But for this, we will need to find out our current IP address at our current network which will help us to serve the website in local network.
So at first step:
We will open our terminal on our PC. For Android user, we need to open Termux app. Then simply type ifconfig to get the IP address of our device in the current network. We will get an output like this one (Here I'm using Android device for development. So output might be something different than this one on your PC terminal but the process is same):
$ ifconfig
Warning: cannot open /proc/net/dev (Permission denied). Limited output.
lo: flags=XX<UP,LOOPBACK,RUNNING> mtu XXXXX
inet 127.0.0.1 netmask 255.XXX.XXX.XXX
unspec 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00 txqueuelen XXXX (UNSPEC)
wlan0: flags=XXXX<UP,BROADCAST,RUNNING,MULTICAST> mtu XXXX
inet 192.168.1.103 netmask 255.XXX.XXX.XXX broadcast 192.168.1.255
unspec 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00 txqueuelen XXXX (UNSPEC)
X= some numbers with our device credentials which is dummied with this variable
If you are using a WiFi router then we will need the wlan0 part to get our device IP. Under wlan0 section there is a subsection of inet showing our current IP! YUP, we need that IP address 192.168.1.103! This might be different for your device and network. This is the key of this mission! Now we're going to the second important step.
So the Second Step is:
That required input command to configure the IP address.
rails s -b 192.168.1.103 -p 8080
Here:
rails s for rails server
-b 192.168.1.103 for bidding the IP address for customisation from the default IP http://127.0.0.1 which is our localhost address.
-p 8080 for port setup. This part is optional. Default port is 3000.
This is the process of changing the localhost IP (http://127.0.0.1) to local network IP which will be available for other device of the same network user.
Now our rails app is available in our local network! Other users in the same network will also be able to visit the website while the server command is running. And the link will be http://192.168.1.103:8080 if you also configure the port number. Otherwise if you have used the command rails s -b 192.168.1.103 without port configuration the link will be: http://192.168.1.103:3000
Again: 192.168.1.103 was for my case, your IP address will be different for your device. That will be needed to use for your server and link address.

how do i run a development rails app / website on an ipod

I have a app / site that i am running on my local imac and i want to test it on my ipad browser.
Can connect to my imac localhost rails app throught the wifi with my ipad ? If so how!! ?
My app is a multi tenant app that uses subdomains and so i use the hosts file on my my to point for example achme.mycompany.dev to localhost.
How do i do this on the ipad to goto achme.mycompany.dev in the browser and it runs the local app on my imac ?
Hope this all makes sense! Please help.
best regards
Rick
I'm providing an update for anyone who's using Rails 4, has followed the steps in the accepted answer, and still can't connect to the app via development_machine_ip:3000. The reason being that somewhere around version 4, Rails changed the default binding address from 0.0.0.0 to only localhost. By default this allows you to only access the Rails app via localhost:3000 or 127.0.0.1:3000 - which is fine in most cases.
Now if you'd like to access the app from a different device on your network, you can use the -b option when starting the server and specify a binding address of 0.0.0.0
rails s -b 0.0.0.0
This will bind on ALL interfaces including localhost and the IP assigned by your network. You should now be able to access the app via development_machine_ip:3000.
I am hoping that your macbook and iPad are on same network. Now go to "Open network preference". Check screenshot.
You will see an ip.
then from ipad open: your_ip:3000
I use proxylocal ngrok for this:
$ ngrok http 3000
ngrok by #inconshreveable (Ctrl+C to quit)
Session Status online
Account Sergio (Plan: Free)
Version 2.2.8
Region United States (us)
Web Interface http://127.0.0.1:4040
Forwarding http://be278635.ngrok.io -> localhost:3000
Forwarding https://be278635.ngrok.io -> localhost:3000
Connections ttl opn rt1 rt5 p50 p90
0 0 0.00 0.00 0.00 0.00
Now you can open http://be278635.ngrok.io from your ipad without worrying about your machine's ip address.
If the subdomain is just going to 127.0.0.1:3000 (or whatever) you should be able to access it the same way by going to your machine's local IP address with the same supplied port number. I look at my rails app on my phone all the time.
If you have virtual hosts or something set up, it's probably going to be more complicated than that.
For this, you would either need to jailbreak your iPad to edit the /etc/hosts file, or add a DNS entry in your router (assuming your router is your DNS server).
One of those two sounds like the easiest.

Resources