"rails s" boots thin but cant access via localhost - ruby-on-rails

I am having difficulty getting rails up and running. I have gotten as far as booting it with the command
rails s
This results in the following output:
=> Booting Thin
=> Rails 3.2.22.2 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
installing dummy notifier
Thin web server (v1.7.0 codename Dunder Mifflin)
Maximum connections set to 1024
Listening on 0.0.0.0:3000, CTRL+C to stop
When I run localhost:3000
I had the line:
config.vm.network "forwarded_port", guest: 80, host: 8080
in my vagrantfile but tried to change this and ran
vagrant provision
but to no avail. Are there any ways for me to test why I cannot access the project. Any guidance would be appreciated. Thanks!
UPDATE:
Having run the command:
bundle exec rake db:create
bundle exec rake db:migrate
bundle exec rake db:seed
I received a few errors regarding deprecation and "ActiveRecord::StatementInvalid: PG::UndefinedTable: ERROR: relation 'capabilities' does not exist"
Would this have anything to do with it not loading correctly?

In your vagrantfile, try to use:
config.vm.network "forwarded_port", guest: 3000, host: 3000

You don't need to run vagrant provision to change port forwarding, you can just restart the box with vagrant reload.
Rails defaults to only binding to localhost, and won't allow connections from other hosts (even a browser on your port-forwarded host). Try starting the rails server binding on all addresses like this:
rails s -b 0

Related

How do i run two rails projects on my machine simultaneously

I want to be able to run two rails servers on one machine via vagrant and virtual box. I have the first set up and when i run
rails s
it returns the following with the site accessibly in my browser at http://localhost:3000/
=> Booting Thin
=> Rails 3.2.22.2 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
installing dummy notifier
Thin web server (v1.7.0 codename Dunder Mifflin)
Maximum connections set to 1024
Listening on 0.0.0.0:3000, CTRL+C to stop
Heres the vagrantfile for this instance:
Vagrant.configure("2") do |config|
config.vm.box = "hashicorp/precise64"
config.vm.network "forwarded_port", guest: 3000, host: 3000
end
I now have the second project in a different folder on my local machine. I have navigated to it initiated my vagrant box, completed all the set up steps and ran rails s again. Here I get:
=> Booting Puma
=> Rails 4.2.3 application starting in development on http://localhost:3000
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
Puma 2.12.2 starting...
* Min threads: 0, max threads: 16
* Environment: development
* Listening on tcp://localhost:3000
Heres the vagrantfile for this instance:
Vagrant.configure("2") do |config|
config.vm.box = "hashicorp/precise64"
config.vm.network "forwarded_port", guest: 80, host: 8080
end
I have been trying to investigate the the fact that it says "listening on tcp://localhost:3000" but if anyone can give me some pointers as to how exactly I can run the two projects from the same machine it would be much appreciated.
You have to run them on different ports. rails s takes a port argument.
rails s -p 3001
will give you a server at port 3001 and so on.
Perhaps try running the second server at port 8080, not 3001, since your second vagrant machine is set up like :
config.vm.network "forwarded_port", guest: 80, host: 8080
I ended up running
puma -b tcp://0.0.0.0:3001
and my vagrantfile had the following:
config.vm.network "forwarded_port", guest: 3001, host: 3001
Thanks for the pointers though as they helped me to better understand the problem and find the solution.

Can't change server address with private_pub on rails 4

I have been using private pub on my local machine and it works fine but now that I'm trying my rails app on a private vps it's a different story. I have been trying to change the server string in the private_pub.yml to the ip of my vps, but I realised that nothing changes no matter what I do. It always keeps serving localhost:9292.
So I tried the same thing on my local machine, I changed the server string to "http://192.168.1.11:9292/faye" in the development and production environments as you can see here (I changed the server adress in both environment just to be sure...) :
### config/private_pub.yml
development:
server: "http://192.168.1.11:9292/faye"
secret_token: "secret"
production:
server: "http://192.168.1.11:9292/faye"
secret_token: "thisisasecrettokenmyfriend"
And when I run bundle exec rackup private_pub.ru -s thin -E production I always get:
>> Thin web server (v1.5.1 codename Straight Razor)
>> Maximum connections set to 1024
>> Listening on localhost:9292, CTRL+C to stop
So why does it not read the server address in the private_pub.yml file ? Is private_pub too deprecated ?
Any answer, suggestion, tip will be greatly appreciated :)
try
bundle exec rackup private_pub.ru -o 0.0.0.0 -s thin -E production
so the server will listen everything

rails 2.3 server running inside vagrant environment not accessible in host machine mac os x browsers

in vagrant I am using:
box 'prorail/centos-5.8-x86_64'
in vagrant i am running rails 2.3 server like:
[vagrant#localhost myapp]$ script/server
=> Booting Mongrel
=> Rails 2.3.5 application starting on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
in my hosts file i have added this line at the bottom
192.168.60.110 www.example.dev example.dev dev.example.com
in Vagrantfile i have added this ip:
config.vm.network :private_network, ip: "192.168.60.110"
in all browsers i have tried following urls
dev.example.com:3000/
dev.example.com
in browser nothing happens . i hav tried all browsers
chrome
tor
firefox
safari
i have tried several other commands to run rails 2.3 server inside vagrant environment but still nothing happens
script/server -b 0.0.0.0
script/server -b 0.0.0.0 -p 3000
script/server -p 3000
log into vagrant environment:
vagrant ssh
than type or copy/paste the following command:
sudo /sbin/iptables -I INPUT -p tcp --dport 3000 -j ACCEPT
this command will allow port to be accessible by host machine. than type:
exit
login again into vagrant and goto your project root. than run:
script/server
now you can access it in browser
www.example.dev

What is localhost and where is it defined?

I just changed from thin to puma at the recommendation of Heroku. When I start my rails app using the puma server it responds:
=> Booting Puma
=> Rails 4.2.2 application starting in development on http://localhost:3000
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
Puma 2.11.3 starting...
* Min threads: 0, max threads: 16
* Environment: development
* Listening on tcp://localhost:3000
However if I go to http://0.0.0.0:3000 in the browser, which was my old localhost with the thin server, it does not respond. However, if I open http://localhost:3000, then it works. It appears that the definition of localhost has changed.
So, what is localhost? In particular, what sort of object is it, how is it defined, how do I see the actual ip address, and why does puma change it?
If you're trying to get Rails to bind to a different ip, the way to do that is with the -b option. To bind it to 0.0.0.0 instead of the Rails-default localhost you'd want to run something along the lines of rails s -b 0.0.0.0
Note: To be explicit, it may not be a bad idea to throw the -p 3000 option in there too (sets the port), even though that default is not likely to change. More info on the available options can be found by running rails s -h as well.
Localhost is the IPv4 loopback IP address 127.0.0.1. It is used instead of the hostname of a computer. Localhost can sometimes mean this computer.
For example, directing a web browser installed on a system running an HTTP server to http://localhost will display the home page of the local website.
Here's an interesting Wikipedia article
https://en.wikipedia.org/wiki/Localhost

Production mode is not running on port 80 (Rails)

I don't understand why it's not running on port 80 instead of port 3000 when I run the command RAILS_ENV=production rails s on the same line. I want it to run in production mode but it's not running on the correct port. Anyone know why? I'm trying to use Rubber but I haven't ran any commands for it only just changed some of the files like it says in this tutorial.
root#ip-000-00-00-000:/home/ubuntu/Git/# RAILS_ENV=production rails s
=> Booting Thin
=> Rails 3.2.11 application starting in production on \http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
\>> Thin web server (v1.5.1 codename Straight Razor)
\>> Maximum connections set to 1024
\>> Listening on 0.0.0.0:3000, CTRL+C to stop
^C>> Stopping ...
Exiting
webrick runs on port 3000 by default(even in production mode). Pass the port number explicitly if you want to run on a different port.

Resources