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

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.

Related

How to run Grails application so that other computers on network can access it?

I've developed a Grails application and I want my coworkers to be able to test it. They are on my network so I figure they can access it by using my IP address and the port number (8080). I've tried running it according to the steps laid out here and here to no avail.
I noticed that whenever I run the program, even when I follow those instructions, it says:
Grails application running at http://localhost:8080 in environment: development
Basic networking stuff here.
When something starts on interface 127.0.0.1 port something
Usually that port is then available for all the interfaces on the machine
if you run netstat -plant you will see running ports open on the machine.
Basically what ever ipconfig or ifconfig tells under Linux as your internal interface something like 192.168.1.x
The app is then available on http://192.168.1.x:8080
If you can't access it from other machines on network start by trying to ping {your machine ip}
It sounds like network security stopping local access from 1 machine accessing another.
Or even better still your good old MS firewall try stopping your security stuff on your desktop
It's not clear if you can access the app yourself on your own machine? It should be available at:
http://localhost:8080/appname
Your co-workers should be able to access the app by changing localhost to your computer name:
http://mycomputername:8080/appname

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.

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

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)

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.

Remotely viewing web pages served by pow.cx

Using WEBrick you could navigate to an app you were serving from another device/virtual machine by navigating to your.ip.address.here:port
Is it possible to do something similar with pow.cx?
The latest version of Pow (0.4.0) now includes xip.io support. You can read about the release here.
Here's a quick explanation of how this helps Pow serve your Rails apps across your entire local network, from their post:
Say your development computer’s LAN IP address is 10.0.0.1. With the
new version of Pow, you can now access your app at
http://myapp.10.0.0.1.xip.io/. And xip.io supports wildcard DNS, so
any and all subdomains of 10.0.0.1.xip.io resolve too.
Here's a description of xip.io, from their site:
xip.io runs a custom DNS server on the public Internet. When your
computer looks up a xip.io domain, the xip.io DNS server extracts the
IP address from the domain and sends it back in the response.
There are basically two options:
Don't use pow: run your applications on localhost as usual and access them as usual
Edit the hosts file (or local DNS) to point your server machine ip
Example accessing from a virtual windows machine:
Suppose you are running two rails applications in pow: store.dev and auth.dev, and you want to access them from a windows xp virtual machine to test them with IE, you only need to edit your hosts file to add the lines:
C:\WINDOWS\system32\drivers\etc\hosts
# Allow to access applications in pow.
# The ip address points to the host machine localhost, that usually is the default gateway
10.0.2.2 store.dev
10.0.2.2 auth.dev
And then open the IE browser to access your applications in http://store.dev and http://auth.dev respectivelly.
Specifically, no, because Pow uses the Host header of the request to determine which app you need to access. To get that working remotely, you would have to have the remote machine map the required domain name to your IP address - either with a local DNS server or by editing the HOSTS file. Both of which are possible but annoying.
The simplest thing to do in that case is to start up a standalone Rails server as you mentioned (using ./script/server or rails s depending on the version), and then you can address http://[ip address]:3000 as before.
In other words, Pow works because it intercepts your local domain resolution, something that isn't affected by (or available to) remote machines.

Resources