Real-Life Rails: Develop with NetBeans, Deploy on Linux : Page 2

Find out how to leverage the Ruby and Rails support in NetBeans 6.0, and then learn some techniques for deploying Rails applications on a Linux server efficiently.

by Mark Watson

Feb 14, 2008

Page 2 of 4

Leveraging NetBeans 6.0 Ruby and Rails Support
The first step toward using NetBeans 6.0 for your Ruby and Rails development is installing NetBeans and the Ruby plugins. Click here to download the Ruby NetBeans version 6.0 bundle I use. Add any optional Ruby and Rails plugins (e.g., if you use JRuby and want to add GlassFish plugins) by running the menu item Tools→Plugins.

Although I do use JRuby for projects that use existing Java libraries (for me, this is mostly artificial intelligence development where I need Java libraries for machine learning, reasoning, the semantic web, etc.), I still use the C version of Ruby for almost all Rails development and deployment. By default the Ruby NetBeans 6.0 bundle sets JRuby as the Ruby system. Change this setting by using the menu item NetBeans→Preferences→Ruby (see Figure 1 for a screenshot from my MacBook. If you use Linux or Windows, you will see something similar.).

Next, you will use the Rails Generator in NetBeans to make your development environment as convenient as possible. Figure 2 shows my Rails CookingSpace.com project (and a few other projects that are collapsed from view while I work on CookingSpace.com). When I right-click on the top-level project (or control-click on a Mac), NetBeans displays a popup tools menu with the standard NetBeans tools on the bottom and the Ruby- and Rails-specific tools added to the top. The top option (Generate...) launches Rails Generator.

Make use of the Ruby and Rails plugins' menu options for running tests inside the IDE, which I find more convenient than using the command line rake tools (see Figure 4).

One of the most useful techniques for interactively developing a Rails web application using NetBeans 6.0 is to run both a test server (WEBrick or Mongrel) and a Rails console at the same time. As you edit and save code you see the changes testing in a web browser on the test server and you can test snippets of code before adding them to your models or controllers. Meanwhile, the console enables you to inspect live data. See Figure 5 for an example of this setup where the panel in the lower right corner has both server and console (currently selected) tabs.

Before proceeding with this article, now would be a good time to either create a trivial test Rails application using your new NetBeans development setup or import an existing Rails application that you have already written. You can import an existing Rails web application by using the menu File→New Project→Ruby→Ruby on Rails Project with Existing Sources.