Accessing Rails From Virtualbox

My latest project involves adding a Flash fallback to replace an HTML5-based feature in a Rails application. It’s the first time I’ve tested in Internet Explorer over a virtual machine, and I spent a good deal of time configuring everything. Here’s a summary of the process for future VM novices.

Get VirtualBox

First, grab VirtualBox. It may be handy for more than testing: in addition to running Internet Explorer, you might want to try a new Linux distro or do some pen testing.

Install an IE virtual machine

Microsoft recently rolled out free virtual machine images for IE testing that greatly simplify the setup process. Download and extract the versions you’re interested in. Some of these are distributed as full images, but most come as several .rar files and a self-extracting archive. To extract from the command line:

1
2
$ chmod +x MacVirtualBox.part1.sfx
$ ./MacVirtualBox.part1.sfx

This should create a new .ova file in the same directory. Open VirtualBox and import it (File > Import Appliance on OS X).

Configure network settings

Select the machine you’d like to connect from and choose Settings > Network. Make sure the network adapter is enabled and attached to NAT. (This should be the default setting).

You can access the host machine from inside the VM at 10.0.2.2–e.g., if you access your Rails dev server at localhost:3000, you can connect at 10.0.2.2:3000. Unfortunately, running my Rails dev server from the host machine resulted in occasional redirects to localhost. Fix this by editing the Windows hosts file.

The Windows hosts file is available in C:\windows\system32\drivers\etc\. In XP, you’ll be able to edit it directly with Notepad. On a Vista VM, you’ll need admin priviliges. Find Notepad in the start menu, right click, and choose “Run as Administrator.” Then, edit the hosts file to direct localhost to 10.0.2.2, the default VirtualBox address for the host machine.

1
10.0.2.2 localhost

Run your Rails dev server on the host machine, and connect to localhost:3000 as usual. Congratulations! You’re ready for the joy of Internet Explorer. For bonus points, configure Capybara to run in IE.

Comments