Running Rails in Windows with Instant Rails

Problem

You develop on a Windows box, and you'd like to install and configure Rails and all its dependencies at one time. You'd also like the entire installation to exist in a self-contained and isolated environment, so that you don't need administrative privileges to install it, and it won't conflict with any software already installed on the box.

Solution

Download and install Instant Rails to get Rails up and running quickly in a Windows environment. You can get the latest release at the Instant Rails RubyForge page at .

Unzip the archive you downloaded, and move the resulting directory to a file path containing no spaces, such as C:\rails\InstantRails. To launch Instant Rails, navigate to that directory, and double-click the InstantRails.exe executable. When it starts, you'll see the Instant Rails status window. Clicking the I graphic in this window displays a menu that serves as the starting point for most configuration tasks. To create a new Rails application, click on the I and select Rails Application → Open Ruby Console Window. Type the following command to create an application called demo:

C:\InstantRails\rails_apps>rails demo

The next step is to create and configure your databases. From the I, select Configure → Database (via phpMyAdmin). This launches phpMyAdmin in your default browser with the URL of . The default databases for the demo application are demo_development, demo_test and demo_production. You'll need to create these databases in phpMyAdmin; you must also create a user named "root" with no password.

Now you can start building your Rails application. To create scaffolding for a cds table that you've created in your database, open a Rails console window, and navigate to the root of the project. To execute a command in the scripts directory, pass the path to the command as an argument to the Ruby binary:

C:\InstantRails\rails_apps\demo>ruby script\generate scaffold cd

To start your applications, open the Rails application management window, and check the application that you want to run. To start the demo application, check the box next to it and click Start with WEBrick. shows the options available in the application management window.

Figure 1-3. The Instant Rails application management window

Access the application in your browser with . To view the scaffolding you created for the cd's table use .

Discussion

Instant Rails is an extremely convenient solution for running a Rails development environment on a Windows desktop machine. It comes with Ruby, Rails, Apache, and MySQL; if the configuration hasn't been taken care of already, Instant Rails makes configuration as painless as possible.

The solution demonstrates starting an application in Instant Rails using the WEBrick web server, but Instant Rails also ships with the SCGI module for Apache. The SCGI protocol is a replacement for the Common Gateway Interface (CGI), such as FastCGI, but is designed to be easier to set up and administer.

See Also