Vagrant and RoR - ruby-on-rails

I'm very new with Rails and I've installed Vagrant to run the Rails server. I've started the server and am able to load localhost:3000, now I don't know where to go. The command line is blank and I read that I should type in "script/console", but all I can really do is ctrl-C or -d.
When I tried to run Vagrant in a separate Window with "vagrant up" it says I need to do "Vagrant init"
Where do I go from here so that I can start going through my tutorials/start developing?

This screencast from RailsCasts should get you started. Some of the suggestions are a bit out-dated but by reading the show notes and comments, you should be able to get up and running. From there you can modify.
While getting Rails set up initially with Vagrant will be work, it's an incredibly handy tool to have experience with. It becomes even more useful when you incorporate a provisioning tool like Puppet.

In your terminal if you are running the webrick server via rails server you either need to background it or open a new terminal to get your shell prompt back. If you ctrl-C out of it you will kill the server. Keep in mind, the webrick server should only be used for local development. It's not a production level web server. See the Rails Getting Started guide for more details.
If you are going to run your rails server in a Vagrant VM, you'll need to configure the port forward in your Vagrantfile so you can access from your host machine.
config.vm.forward_port 3000, 9080
There error you are seeing would be from you running vagrant up in a directory that doesn't contain a Vagrantfile.

Related

Run Rails application in AWS Cloud9

Recently I migrated my workspace from the old Cloud9 to AWS Cloud9. Now I can no longer run my application. I'm hoping somebody on Stack Overflow might have an idea what the problem is because AWS' help forums and documentations skip past the parts I'm missing.
The "Run" button tries run the last file that I was viewing and editing, rather than my application as a whole.
So I try to start it running in the terminal with "rails s -b $IP -p $PORT". I get this line:
Listening on tcp://127.0.0.1:8080
So the program should be running, right? But the green "Run" button is now disabled, and I don't get the spinning icon in my terminal window that I used to get with old Cloud9.
Next I try getting the application's url from the "Share" menu, which is:
18.212.63.5
When I try to navigate to this url in another window, I get an error
ERR_CONNECTION_TIMED_OUT
When I try to "Preview Running Application" with the IDE, I get the error
66af0558a4b44f8bb019cb5628f6b28f.vfs.cloud9.us-east-1.amazonaws.com refused to connect.
In related news, I'm highly frustrated with AWS for a lot of other reasons. Should I consider switching to a different IDE? Or keep trying to learn this one?
Thank you in advance for any insight.
See also https://forums.aws.amazon.com/thread.jspa?messageID=899522, which provides a set of diagnostic commands that you can run from a terminal session in the AWS Cloud9 IDE for your development environment that can output the incoming traffic rules for the environment's associated Amazon EC2 instance's security group and network ACL. These traffic rules need to allow incoming traffic for the correct protocol and port.
I had what I believe was a similar problem. The preview won't show if the app is being served over http, rather than https:
https://docs.aws.amazon.com/cloud9/latest/user-guide/troubleshooting.html#troubleshooting-app-preview-http
A simple workaround here is just to remove the 's' from the amazonaws.com URL listed in the 'refused to connect' error, and then press the button to preview the application in a browser tab.
Also note that on AWS C9 you shouldn't need
rails s -b $IP -p $PORT
It should usually be enough to do
rails server
(though check that, for example, your puma.rb file is set to run on port 8080 rather than 3000)

Running two puma servers at once for the same rails project, force kills one of the servers?

I would like to run two Rails servers from the same directory, on different ports. Here's what I have tried:
rails s, which starts my server on port 3000.
In another terminal tab, I run puma -p 7676, which starts another server on port 7676.
No matter what order I run these commands, whether I switch out puma for rails s, one of the servers always gets shut down.
The error it shows is:
A server is already running. Check /Users/<username>/<appname>/tmp/pids/server.pid.
Now, following several stack overflow answers, it seems you can tell the command where it should look for the pid:
rails s
rails s -p 3007 -P `pwd`/tmp/pids/alternative_server.pid
This fails with the exact same error:
A server is already running. Check /Users/<username>/<appname>/tmp/pids/server.pid.
So far my only recourse has been to clone my project in a seperate directory and run the server from there. This is obviously not ideal since I need to keep pulling any changes I make on the branch.
Versions:
Puma: Version 3.6.0 (ruby 2.3.1-p112)
Rails: 5.0.0.1
You need to comment plugin :tmp_restart in config/puma.rb.
This is source code of this plugin: https://github.com/puma/puma/blob/master/lib/puma/plugin/tmp_restart.rb

Rails server will not stop and even if it is running it is not working

I am new to Ruby on Rails, but I managed to install it using the RailsInstaller and I am using Aptana Studio 3 as a text editor. I am on a Windows 7 x64.
Last week I managed to create a simple Hello world project, and it worked as it should when starting and stopping the rails server. To start the server I used the command rails server and to stop it I used CTRL+C.
Somehow, this week, when I'm trying to start the server it says "A server is already running". But, when I go to the correct page in a web browser it doesn't work. I get the error "Google Chrome could not connect to localhost:3010". So, this makes it seem like the server is not working, even though it supposedly is running.
So, I then try to stop the server from running, but CTRL+C doesn't seem to do anything. It doesn't give any kind of message at all when I input that, it just skips to a new line in the terminal window.
the standard port is 3000.
You can kill the server in the task manager and start it from new..
There is probably a rails process still running but bugged out/crashed. Try looking at the processes in the windows task manager to for a rails process, and cancel it. Additionally you can start a rails process on a different port with rails server -p PORT

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

how to deploy ruby on rails application in xampp in windows xp?

I'm very new to Ruby environment ..
I want to run my Ruby on rails Application in apache in xampp on windows xp rather than WeBrick server which is in-built for ruby on rails...
I tried it by adding Virtual host in apache- http.conf file
When i run my application i'm able to see "Welcome Abroad"....
But when i click on "About your application’s environment"
it was showing error like the following
Object not found!
The requested URL was not found on this server. The link on the referring page seems to be wrong or outdated. Please inform the author of that page about the error.
If you think this is a server error, please contact the webmaster.
Error 404
localhost
9/9/2011 10:47:31 AM
Apache/2.2.17 (Win32) mod_ssl/2.2.17 OpenSSL/0.9.8o PHP/5.3.4 mod_perl/2.0.4 Perl/v5.10.1
To deploy your app with apache you need to use phusion passenger http://www.modrails.com
There are plenty of how-to's around the web and the documentation is good enough to get the service running.
This means your Ruby on Rails server is NOT running.
You need to run your server first.
I made a batch file, start-server.bat which contains
d:
cd "D:\Ruby\Web\rails1"
"C:\RailsInstaller\Ruby1.9.3\bin\ruby.exe" script\rails server
then check the PORT number of the server that is running,
So since the port on the screenshot says 10524, you can run it on
http://localhost:10524/

Resources