I know – the above app isn’t much, but oh, the time it took me to get it working!
I’ve been trying to follow a Lynda.com video tutorial on Ruby on Rails – just the part about getting started! – for a couple of weeks now. The first stumbling block is that the tutorial was done on a Mac, and it doesn’t give very detailed advice for Windows users. (I am running Windows Vista, not as a lifestyle choice, but because I am poor. Don’t judge!) Here is what I tried:
- Downloaded InstantRails. (Go ahead – just try to find their download page! I dare you!) Although everything seemed to be working here, commands like “script/generate controller say” didn’t work. Well, if that doesn’t work, it’s a wash.
- Installed Ubuntu as a virtual machine. Followed several tutorials on how to install RoR, but all seemed to leave me with database connection problems.
- Installed Turnkey Rails as a virtual machine. Oh, the joy I felt when I realized that to view my RoR app, I needed to use the browser on my non-virtual machine (i.e., Vista)! Why isn’t that made explicit anywhere? Once you figure that out, the GUI for Turnkey is really great – and the documentation is crap. I could not connect properly to the database with this one either.
- Installed Bitnami as a virtual machine. Ugh, this is one is frustrating. I don’t even want to talk about it. The documentation is worse than for Turnkey.
So, one InstantRails and three virtual machines later, I was about ready to give up. However, I was feeling a bit better informed about how RoR functions because of all my failed interactions with it, so I decided to give InstantRails one more try. For anyone out there who is struggling and Googling vainly, here is what you do:
- You’re starting with a Windows Vista system.
- Download InstantRails. Choose the .zip file closest to the top of the page.
- Extract InstantRails somewhere convenient, such as a folder on the desktop. It’ll be staying there, rather than installing itself somewhere else. Get yourself a beverage because the extraction will take some time.
- Open the extracted folder and double-click “InstantRails.exe.”
- A dialog box will pop up. Just agree to let it do its thing.
- The program will look like this:
- If MySQL doesn’t say “Started” after a few seconds, click “MySQL” and choose “kill.” That should fix it!
- Now, to build your very own “Hello World” app, click the “I” button on the far left.
- Choose “Rails Applications” -> “Manage Rails Applications.”
- There are some prebuilt applications here that you can play with, but let’s face it – that’s not why you’ve installed RoR. Click “Create New Rails App…”
- A command prompt will pop up. Type the command below, where “myapp” is the name of the app you are going to create:
- A list of lines should be spat out, each starting with “create.” Go back to the “Rails Applications” window and click “Refresh” at the bottom. “myapp” should now appear in the list.
- Go back to the command prompt and type the following command to change into the directory of your new app:
- Type the following command to generate a controller called “say.” Note that you need to start the command with “ruby” or it won’t work! The direction of the slash doesn’t seem to matter, however. (Both \ and / worked for me.)
ruby script\generate controller say
- Now you can edit the “say” controller to define an action called “hello.” Inside the InstantRails folder on your desktop, use a text editor to open “rails_apps” -> “myapp” -> “app” -> “controllers” -> “say_controller.rb.”
- Add two lines to make it look like this:
class SayController < ApplicationController def hello
- Save the file and navigate to “rails_apps” -> “myapp” -> “app” -> “views” -> “say.” Make a new file here called “hello.html.erb” that contains the following text:
- Back in the “Rails Applications” window, check the box next to your app, and click “Start with Mongrel.”
- Your app is now running, but how to view it? Click “Configure Startup Mode” to find the address to put into your browser. Mine is http://127.0.0.1:3000. Put that address in to get the standard “Welcome Aboard” page. Append to it the name of your controller and view to see your app in action:
- That’s it! You’ve got InstantRails working, and it’s time to actually learn RoR now. At least, that’s my plan!