Monday, June 3, 2013

Setting up Command Prompt with Ruby on Rails on Windows 8

I've been getting started with Ruby on Rails for the last few days. There are a lot of guides out there, but some try to accommodate for both Mac and Windows, and it can get confusing. So here's a Windows-only guide to get you started.

1) A tutorial website called Treehouse has a great video tutorial - and it's just over 2 minutes to boot. So visit their Windows-only tutorial for installing rails. They will show you how to use Rails Installer to set up several important things at once.

2) I did run into a few obstacles with that guide, although it is a good outline. When following along with their instructions, they will have you type "ruby -v" and "rails --help" in your command terminal. This part was troublesome for me: The console returned "access denied." To solve this, make sure your firewall is allowing the necessary programs access to their communication points. View the event log in your Firewall. Depending on which Windows you have, search how to find your firewall as necessary. The Windows firewall hub will tell you whether Windows or another program (McAfee, Norton) is handling your firewall security. Make sure access is granted regardless of what program is handling your firewall.

This should be enough to get Ruby on Rails installed on your system. If you are unsure of how to start practicing, you can continue with the next free video on the site we initially learned from. To continue:

3) To access the tutorial on creating a simple RoR application, visit this Treehouse link. As useful as I've found the tutorials to be, there are some tweaks that I found necessary, especially running Windows 8. However, here's the cure to the potential headache.
  1. When the instructor says directory, he means what is also called a folder (as in, a folder but not a "file.") I'd be more than happy to tell you how to make a directory, but here are two resources that will save us both some time: First visit http://ruby.learncodethehardway.org/book/ex0.html, then head over to http://www.cs.princeton.edu/courses/archive/spr05/cos126/cmd-prompt.html. The latter will tell you how to make directories from right within command prompt, and the former will tell you what to do with this knowledge. 
  2. When the instructor at Treehouse mentions "rvm use 1.9.3", that step is not necessary for Windows (at least if you followed the steps I've outlined in this post.) If you try in Windows, you will likely get an error.
  3. Continue with the Treehouse instructions, but if you get another error with "rails server", be sure to read what it says. It will likely say (among many other things) "Run bundle install". So type in "bundle install" and be on your way. 
  4. Set up your server as shown in the video. Remember to access port 3000 with 127.0.0.1:3000 rather than 0.0.0.0:3000 (just type it in your URL bar of any browser.)
  5. If you've gotten this far, keep on going; Great job! Now it's time to test your statuses update. If you are on Windows 8, you may get the following error: "ExecJS::RuntimeError in Users#index". Easy fix. Head over to http://stackoverflow.com/questions/13530042/execjsruntimeerror-in-usersindex-ror, and find the answer by Kevin P. (It's the one that gives 3 options.) The third option helped me out, and one JBickford helpfully told us that for if we used Rails Installer as in the videos, then the necessary file is at C:\RailsInstaller\Ruby1.9.3\lib\ruby\gems\1.9.1\gems\execjs-1.4.0\lib\execjs\ru‌​ntimes.rb . Just edit it with Notepad, Notepad ++, or any other simple code editor.
  6. Go and check that your status updates are working. 
Now you should be up and running with Rails, now how to set up and end a simple server, and have some basic CMD commands under your belt. I mostly wanted to put all the resources that helped me finish the lesson into one place, so that it would be easier for others to follow. Any questions, just let me know.