Rails server runs, but not all browsers actually show the page - ruby-on-rails

I'm developing a Rails 4 app on Mac OS 10.6.8, and yesterday I started getting errors -- but only in certain browsers, and for certain URLs.
Everything looks fine in the Terminal:
$ rails s
=> Booting WEBrick
=> Rails 4.0.1 application starting in development on http://0.0.0.0:3000
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
[2014-02-24 12:43:47] INFO WEBrick 1.3.1
[2014-02-24 12:43:47] INFO ruby 2.0.0 (2013-06-27) [x86_64-darwin10.8.0]
[2014-02-24 12:43:47] INFO WEBrick::HTTPServer#start: pid=41543 port=3000
But http://0.0.0.0:3000/ in Chrome or Safari produces a 403 error:
403 Forbidden
hefishkUtZiafopyoshGeOnnIbDoufye
That address opens in Firefox, though.
I also tried another address, http://localhost:3000/. Previously, Chrome displayed "No data received" with a frowny face and two buttons, "Reload" and "More". Now it works fine in Chrome. It also works in Safari and Firefox.
Opening http://127.0.0.1:3000 works in Chrome, Safari and Firefox.
This is more of a bump in the road than a blockade, but its randomness is troubling. I don't think I substantially changed my Rails app in the meantime. I even created a new Rails project and got the same error messages.
Also, I've seen other questions on SO where all three addresses suddenly don't work, and just as suddenly start working again later. I'd like to know if there's a better fix than just waiting.
Any help would be very much appreciated.

0.0.0.0 means rails is listening on all interfaces on your box.
When you're accessing the application, pick a specific one (localhost / 127.0.0.1 or your actual IP (you'll have multiple IPs if you have more than one physical or virtual network interface).

Related

Can't connect Rails-project to localhost when computer is connected to internet

I just recently begun having the problem that I'm only able to visit localhost:3000 when wifi is turned off and computer is disconnected from the internet.
As soon as I turn on wifi and connect the computer to an internet connection, chrome just says "connecting" in bottom left corner of browser window. There are no errors present.
I've tried on three completely different connections. Home wifi, office and hotspotting via phone.
I have also tried on several different Rails-projects, both rails 5 and below. So it doesn't seem to be project-related.
I have also tried booting the server using my computers IP address as well as 0.0.0.0, and as well as on a different port than :3000. I've also tried in different browsers.
If it is to any use:
=> Booting Puma
=> Rails 5.0.1 application starting in development on http://xxx.xx.xx.x:3000
=> Run `rails server -h` for more startup options
[Simple Form] Simple Form is not configured in the application and will use the default values. Use `rails generate simple_form:install` to generate the Simple Form configuration.
Puma starting in single mode...
* Version 3.7.0 (ruby 2.2.4-p230), codename: Snowy Sagebrush
* Min threads: 5, max threads: 5
* Environment: development
* Listening on tcp://0.0.0.0:3000
Use Ctrl-C to stop
Observation:
This error does not affect rendering partials asynchronously inside the view. That is as smooth and quick as it use to be. This only happens when trying to go from projects/:id/edit to projects/new for instance.
If, as you say, there are no errors and AJAX calls are working smoothly, I'd say that you are using an asset that is fetched from the internet but is not available right now. While the internet is working, the application will keep waiting for a response from the remote server.
When you disconnect from the internet and load the page, see if you get any errors in the browser console about failing to fetch something and try removing it from your application. Let me know if this turns out to be your issue.

Problems connecting to rails server

I'm working at getting a very basic ruby/rails environment up and running, and I am presently unable to connect to it.
I'm working on a Macbook (updates current), and I've got an Ubuntu VM running that I'm using as my test server.
I have port-forwarding set up for connecting with the VM (hypervisor = VirtualBox)
8083 to 80 (http)
9307 to 3306 (mysql)
2223 to 22 (ssh)
3010 to 3000 (WEBrick)
VM Port-Forwarding Setup Screen
I have not setup a firewall on the server
Using this, I can ssh in, and I can hit "non-rails" sites just fine via Apache. What I can't do is get a basic "hello-world" screen up for the rails environment. I CAN get there if I cut out the VM and start WEBrick ("rails s") directly from the Mac environment and then go to localhost's port 3000, but when I attempt the same thing on the VM and then try to hit port 3010 the same way, I get back a "no data received" response.
WEBrick appears to be running just fine
myserver$ rails s
=> Booting WEBrick
=> Rails 4.2.5.1 application starting in development on http://localhost:3000
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
[2016-02-08 09:01:30] INFO WEBrick 1.3.1
[2016-02-08 09:01:30] INFO ruby 2.1.5 (2014-11-13) [x86_64-linux-gnu]
[2016-02-08 09:01:30] INFO WEBrick::HTTPServer#start: pid=3756 port=3000
Turning Apache on/off does not change anything beyond changing the accessibility of the content served by Apache.
I've tried monitoring "log/development.log" in my rails application, and I've also poked around to see if I noticed any clues in any of the various log files under "/var/log", but nothing's jumping out at me.
I am not doing anything fancy here. I just want to get to the "Welcome Aboard!" screen for rails. I thought that getting started would be as simple as setting up the port-forwarding, creating the rails-application, and hitting it from my browser; it's been a few hours now and I'm getting nowhere with this. Apologies if this has a super easy solution that I'm just not seeing.

Rails server is running, but cannot connect to localhost:3000

I am learning Ruby on Rails with railstutorial.org
I had set everything up and working fine from Chapter 1. However, all of a sudden my next app has an issue.
I run "rails server"
=> Booting WEBrick
=> Rails 3.2.9 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
[2012-11-15 00:45:08] INFO WEBrick 1.3.1
[2012-11-15 00:45:08] INFO ruby 1.9.3 (2012-11-10) [x86_64-linux]
[2012-11-15 00:45:08] INFO WEBrick::HTTPServer#start: pid=2752 port=3000
Seems to be working fine, just like with my previous app.
However, I try connecting to localhost:3000 , 0.0.0.0:3000 , 127.0.0.1:3000 on various browsers and they all cannot establish a connection to the server.
Some things to note:
-I was able to connect to localhost just a while ago--it just seems like it suddenly stopped working out of the blue.
-My first app was working perfectly fine, but now it doesn't work for my first app either.
-I don't have firewalls blocking the port, and my hosts file is not the problem.
-I am on Ubuntu 12.10
I almost always find solutions via search, but not this time.. so I need some help please. It's very frustrating as I feel like it's a simple problem that I spent way too long being stuck on.
Thank you.
Try running it in some other port like say 3001 as:
rails server -p 3001
If its working than than try it again on 3000 as the command above.
I thing some other software is using your 3000 port that's why its not responding.
Or for some advanced things see here
with rails 4.2.0, the server binds to localhost by default, instead of 0.0.0.0. When working with a rails in a virtual box, accessing the server from the host computer, the binding address needs to be 0.0.0.0
Start rails server with -b0.0.0.0 to make the rails server accessible from the host computer/browser.
http://guides.rubyonrails.org/4_2_release_notes.html#default-host-for-rails-server
https://github.com/samuelkadolph/unicorn-rails/issues/12#issuecomment-60875268
Make sure you run rake db:create before launching rails s.
I'm using rails 5.0.0.beta3 and was running into this issue. #andrewleung's answer helped me a lot.
It seems like Rails default binding address is messed up on my computer (macOS 10.11.6) ; on some others, it works fine.
The simple solution is just to use rails server -b 127.0.0.1. You can then access your localhost:3000.
My guess here is (hinted from https://serverfault.com/a/544188) that localhost binding is messed up on my computer whereas 127.0.0.1 is more specific.
I had the same issues and i realized it was in the config/environment/production.rb file where config.assets.compile = false must be changed to config.assets.compile = true
However this might in a way render some javascript and sass elements unworking
The issue that it turned out I was having was that my VM had run out of hard drive space and there wasn't even enough left to create the server.pid file. For some reason though, it wasn't throwing an error for this, as the file was being created, but was left blank.
I run into the same issue. It turned out that browser-sync is also running on localhost:3000.
Due to some Rails developer would use browser-sync to test out the front end scripts quickly, I think that could be a popular reason that port 3000 is used.
check your /etc/hosts file..is ip 0.0.0.0 or localhost pointing to some other address.
for me...I was behind a proxy at work and had to do rails s -b 0.0.0.0 -p 3000

Rails only responds when accessed from local machine

I'm running a Rails application on a Mac Mini server machine (with Webrick, running ruby 1.9.2 using rvm). It works fine when I run it locally on my MacBook, and it was working before I reinstalled rvm, but now whenever I try to access it from a browser on my local machine, it simply hangs and doesn't respond.
If I do a curl http://0.0.0.0:3000 on my server, though, I get the webpage back fine.
I created a fresh Rails app just to double-check it wasn't a problem with my app, and I get the same problem. I also get the problem with Mongrel, and if I try running a bare Sinatra app with Thin.
It sounds like the same problem documented here: Webrick is very slow to respond. How to speed it up?, but I tried modifying my config.rb file to use :DoNotReverseLookup => true, and it didn't help.
Any ideas?
I don't think the issue is related to Rails or your dispatcher. It looks like the OS firewall is blocking ingoing requests to port 3000. Did you try to allow all ingoing connections from your System Preferences ?

Rails server not working?

I'm following the first Ruby on Rails 3 tutorial from PeepCode and at around 27-29 minutes in, they have us start the Rails server. To the best of my knowledge, I have Rails (and Ruby) successfully installed.
When I run the command rails server (from Windows 7 Command Prompt per the instructions of the video), I get the message:
=> Booting WEBrick
=> Rails 3.1.3 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
[2011-12-02 18:37:57] INFO WEBrick 1.3.1
[2011-12-02 18:37:57] INFO ruby 1.9.3 (2011-10-30) [i386-mingw32]
[2011-12-02 18:37:57] INFO WEBrick::HTTPServer#start: pid=5584 port=3000
And it doesn't return to the prompt, indicating that it is running. Also, to me (and compared to the video), this looks like a successful message.
However, when I browse to the URL, http://0.0.0.0:3000, as directed by the video, I get an error (while the video opens to the default index page for Ruby). The error I get is:
Error 108 (net::ERR_ADDRESS_INVALID): Unknown error.
Since I'm using Google Chrome, it also says:
The webpage at http://0.0.0.0:3000/ might be temporarily down or it may have moved permanently to a new web address.
So, I was wondering how to fix this?
0.0.0.0 is the ip address that Webrick is binding to. It means 'listen on all interfaces'. In other words, you can connect to this application from the internal address (localhost or 127.0.0.1) as well as the external address on the network (192.168.1.x or 10.0.10.x or a domain name that resolves to an address this machine has on the network). The server doesn't care where the request comes from.
If, however, you started rails server with the '-b' or '--binding' option and told the server to bind to 127.0.0.1, the server would not respond to requests to the external interface. You could still use 127.0.0.1 or localhost but you could not connect to this server using it's external ip address locally or from another machine.
Going to http:// 0.0.0.0:3000 works on my Linux system and most likely the screencast you were watching was using a mac which would also work. My guess is that 0.0.0.0 isn't supported on Windows.
Just use localhost if you are on the box or the ip address of the box if you are accessing it from another machine. That is what I do, even when I'm running a machine that understands 0.0.0.0.
You can start the server with this command:
rails server -b localhost
But as a lazy typist, in my .bash_aliases, I have this alias
alias rs='r s -b localhost'
With the alias, I can start the server with just:
rs

Resources