Access Rails Development Server From A Different Computer - ruby-on-rails

I'm using webrick to develop my rails app on Mac OS X Lion. I'm trying to access the site from another computer (for testing). The internal IP of my computer is 10.1.10.100.
Accessing 10.1.10.100 displays the page served by the apache server running on my computer.
Accessing 10.1.10.100:3000 times out, both from my computer and from another computer on the same network. I can ping 10.1.10.100. From my computer, loaclhost:3000 displays the app.
Is there are firewall I need to open up on Mac OS X or some other setting that needs to be applied?
Thanks

While starting the webrick server specify the IP on which your rails application will run (10.1.10.100 in your case) using -b option, it binds Rails to the specified IP.
rails server -b 10.1.10.100 -p 3000

Related

How to access the local machine's serial port data using a Heroku application

I have an existing Ruby on Rails Heroku application. I want to get the serial port data from the COM 1 port in a Windows computer using this application, but since Heroku is a cloud-based platform running on a Linux server, I am unable to get serial port data from the local machine where the Heroku application is running. If I run the standalone Ruby code on that Windows machine, then it works fine and I am able to get my desired data.
I am getting the following error
Unable to open COM1
How do I solve this issue?
The part of code of my Rails application through which I am accessing serial port data is:
port_str = 'COM1' #may be different for you
baud_rate = 2400
data_bits = 8
stop_bits = 1
parity = SerialPort::NONE
sp = SerialPort.new(port_str, baud_rate, data_bits, stop_bits, parity)
i=sp.gets.chomp
puts i
This code is working fine if I run it on that local machine. 'serialport' gem is there on my gemfile.
Rails is a web server technology that runs on a web server. It builds HTML pages that get sent to a client computer and are rendered by the browser.
When you run Rails locally you are mimicing a real web server - localhost is basically running a web server on your local machine. That is why you can cheat and use Ruby code in your Rails app that locally can access the port of your local machine, but once you run your Rails app on a real web server (like in Heroku) you cannot do this, so you have the wrong tool for the job you are trying to do.
Not only that but since Rails is a web technology you have a web application that runs inside the browser and you cannot easily access the port on a client machine from a web browser. More information on that is in "How to read serial port data from JavaScript".
The ONLY reason your Ruby code is able to access the port is because it is not running in the browser when you run on localhost but it is running inside the web server that gets fired up on localhost, so when the app runs on a real web server that Ruby code will try to access the port of the server not any client machine.

run rails app with an ubuntu server with global ip

Currently, we are running our rails app, on AWS but we tried to move it to Heroku, which didn't work at all, now We are trying to run the app on Virtual Machine on hetzner. I can run the app on local server easily, my question is that, How can we run our rails app with a specific IP and then we can access that app anywhere in the world from that ip? is that possible to do so? We are using PUMA for server.
Yes, you can access to to your site with specific IP.
In description of hetzner Virtual Server says that server have 1 specific IP. So than you deployed and run you application y can access to app with 1.1.1.1:80 or another port.
If i understand you. Also what happened with heroku?

Can’t access rails app on Mac host from VMware Fusion Guest

I’m probably doing something stupid here, but....
I can’t access a rails app running on my Mac from a Windows 10 VM. I have set the network adapter to "Share with My Mac". I can access a PHP site running on my mac via http://[my-machine-name].local or http://[my-ip-address]. But if I specify port 3000 to view my rails app I get an error message (to the effect that [my-ip-address] refused to connect) even though the app is running. I don’t know if this is an issue at the Mac end (though my firewall is off for testing), the windows end, or to do with my VMWare network adapter setting. Any assistance gratefully received
Peter
Just use the -b flag while running your rails app like rails server -b 0.0.0.0:3000 so it gets bound to the whole network interfaces and it can be accessed from outside

Rails application not visible to local network

For the first time since upgrading to OSX Yosemite, I need to view an app running on my machine from another machine on the same network. Previously, this was as simple as finding my internal IP address and using that with port 3000, eg. http://192.168.0.111:3000.
However, I am now finding that with Yosemite this doesn't work. The application is definitely running and is available via localhost:3000 but not via my internal IP.
I have run the network utility port scanner and it shows that localhost exposes port 3000 but my IP doesn't. Other machines on the network that have yet to upgrade (10.7.5 and 10.9.5) are not having this issue.
Any help would be greatly appreciated.
Edit: According to the security and privacy pane of the system preferences, the Yosemite firewall is currently off - so that isn't causing the problem.
By default, rails server will only accept connections from localhost. You can check this by looking at the console output:
Listening on localhost:3000, CTRL+C to stop
To listen on all addresses, which will allow you to connect from other machines on the local network, you must explicitly bind to a more permissive address. Try this:
rails server --binding=0.0.0.0
You should now see:
Listening on 0.0.0.0:3000, CTRL+C to stop
Now you can connect to your Rails app from elsewhere on your local network, by browsing to e.g. http://192.168.0.111:3000.

Virtualbox rails server only accessible externally for some applications

I have an xUbuntu(14.04) virtualBox(4.3.15) server running on Windows 7. I have a 2 sites on the server and when I run rails server for either application it can be accessed internally at localhost:3000 without issue. However, when I access one app externally from a browser on the windows machine at the [virtualbox ip]:3000 the site renders without issue and the other displays 'cannot connect'. Additionally I can ping [virtualbox ip]:3000 for the one site, but the other will receive no response. Just the [virtualbox ip] can be pinged successfully when either site has rails server running.
Both sites are Rails 4.2.0.rc2, Ruby 2.0.0, and WEBrick 1.3.1.
Is there something that needs to be setup specifically so that the 2nd site works?
Haven't been able to locate any differences between the two which might cause an issue.
Was able to determine what the issue was. The one app was starting on http://0.0.0.0:3000 which to my understanding means it is listening on all interfaces, while the other app was starting on http://localhost:3000. The localhost app was therefore not listening for external requests. The solution was to start the rails server with the following.
rails server -b 0.0.0.0
This binds the app to the 0.0.0.0 ip address and I can now access it outside of my virtualbox xUbuntu instance by using [vm ip address]:3000 as the url.

Resources