The Source for Java Technology Collaboration
User: Password:



Brian Leonard

Brian Leonard's Blog

Instant Rails with NetBeans

Posted by bleonard on March 19, 2007 at 11:24 AM | Comments (8)

Two weeks ago I introduced myself to Ruby on Rails, which was, technically, JRuby on Rails. Based on some constructive comments by David Rupp, I've spent some time over the past week doing some additional research on rails. In the process I began to look at pure Ruby (not JRuby).

Now, I'm sorry, this blog entry is somewhat Windows biased, which feels odd for a guy that normally talks about Java. However, playing with Ruby for the past week I realized the easiest way to get up and running with Rails on Windows is to use Instant Rails, which contains everything you need in one nice package: Ruby, Rails, Mongrel and MySQL.

Setting Things Up

Instant Rails

  1. Download and extract Instant Rails.
  2. Run InstantRails.exe. The first time InstantRails.exe runs, it will want to update the paths in the Rails configuration files to the location you extracted the archive. InstantRails starts Apache (which you can stop) and MySQL.



  3. Create an environment variable named RUBY_HOME that points to the Ruby location within Instant Rails. For example: C:\Software\Ruby\InstantRails-1.6-win\InstantRails\ruby.
  4. Add %RUBY_HOME%\bin to your Path environment variable.

NetBeans

  1. Download and install NetBeans 6.0 M7 or greater.
  2. Download and save the MySQL JDBC driver somewhere on your workstation. We need this to use the NetBeans Database tools with MySQL.
  3. Start NetBeans and switch to the Runtime tab (Ctrl+5).
  4. Expand the Databases > Drivers node and right-click to add a new driver.
  5. Browse to the location where you saved the MySQL JDBC driver. NetBeans will detect the driver class and recommend a name:



    Click OK.
  6. Right-click the MySQL (Connector/J driver) now listed under Drivers and select Connect Using. Instant Rails comes with a sample database called cookbook, that we can use to test our connection:



  7. If all goes well, you should be able see your connection and browse the database:




  8. Install the Ruby module from the update center (found in the Features folder. Many dependant modules will come along). The Ruby module requires a restart of the IDE.
  9. The Ruby module also installs JRuby and Rails. However, we're going to point NetBeans at the location where Instant Rails installed Ruby. Open the Options dialog Under Miscellaneous, expand the Ruby Installation node and point NetBeans to the version of these files found in instant Rails installation


    .

Test the Installation

Instant Rails comes with a sample cookbook application which we'll set up in NetBeans. This will also serve as an example of how to set up existing rails projects you already have in NetBeans.

  1. Create a new Ruby on Rails Project From Existing Sources.
  2. Browse to your Instant Rails installation directory where you'll find a rails_apps folder. Select the cookbook folder under rails_apps and click Finish.
  3. The project will open in NetBeans and the Mongrel server will be started (The Output window says WEBrick, but it's actually Mongrel that's running. Also, the server is started even though the Output window just says STARTING. This issue has been logged.).
  4. Try the following: http://127.0.0.1:3000 and you should see the Online Cookbook.


  5. If you run into problems, check that you can verify the Instant Rails setup from the command line.

Create Your Own Rails Project

  1. Create a new Ruby on Rails Application project and click Finish.
  2. Right-click the Controllers folder and select Generate. Name the controller MyTest. NetBeans will run the script to generate the controller.
  3. Open the MyTestController class and add the following:


  4. Press F6 to run the project and browse to http://127.0.0.1:3000/My_Test. You get a Routing Error.



    This is because the Mongrel (and WEBrick for that matter) web server is only capable of handling one application at a time. It needs to be restarted when we switch to another application.
  5. Since we're letting NetBeans start the server, the only way I know to kill it is to kill the ruby.exe process using the Windows Task Manager. Kill ruby.exe, press F6 to run the project, and browse to http://127.0.0.1:3000/My_Test.

Another Way To Run Mongrel

Since NetBeans doesn't yet provide the best integration with Mongrel, you may prefer to run it from the command line. Let's see how this works.

  1. First, kill the ruby.exe again started by NetBeans.
  2. Open the command prompt to the location of your Rails application above. It should be named RailsApplication1 if you accepted the default name.
  3. Type ruby script/server (if ruby isn't found, make sure you set up your path correctly as described under setup above).



    Now you see there's at least a cleaner way to stop the server.
  4. To run the cookbook application, CTRL-C to stop mongrel, switch to the cookbook directory and run ruby script/server again.

Bookmark blog post: del.icio.us del.icio.us Digg Digg DZone DZone Furl Furl Reddit Reddit
Comments
Comments are listed in date ascending order (oldest first) | Post Comment

  • Using native Ruby (not JRuby) in NetBeans has been broken for a while on Unix; I didn't realize it was working on Windows. In any case, I've just checked in fixes which makes native ruby work for me (on OSX). This probably won't hit the daily update center for a couple of days, but if anyone is having difficulty with this on Unix, get a fresh build - see http://wiki.netbeans.org/wiki/view/RubyInstallation.

    Posted by: tnorbye on March 19, 2007 at 01:33 PM

  • Excellent tutorial, thanks! I have the latest NetBeans with Ruby support installed, and the instant rails was installed for quite some time already. So, no more excuses for me :)

    One thing I noticed that Ruby on rails is much, much slower under Windows. Basically, my old laptop with Linux outperforms my 3Ghz dual core PC with Windows XP, which surprises me to no end. Do you see similar performance for RoR on Windows?

    Posted by: vsizikov on March 20, 2007 at 02:22 PM

  • Excelllent! - I can't wait to try this at home...

    Posted by: jonbruce on March 20, 2007 at 03:37 PM

  • To this point I've only been running Rails on Windows, so I have nothing to compare it to, unless you're talking about Java EE, which is another story :-).

    Posted by: bleonard on March 21, 2007 at 09:43 AM

  • This was perfect timing! I've been wanting to try out the NetBeans Ruby support, but just hadn't yet gotten around to it. And for me, the icing on the cake was that you used Instant Rails (I'm the guy who created Instant Rails)!

    Posted by: curthibbs on March 22, 2007 at 10:59 AM

  • That's fantastic that Ruby integrates so nicely into NB. But how about integrating into NB 5.5...or maybe 5.5.1? Also, do you know how I can connect Ruby to Java DB/Derby?

    Posted by: joconner on April 13, 2007 at 01:58 PM

  • The Ruby module is taking advantage of all the new language infrastructure improvements improvments coming in NetBeans 6.0. Unfortunately, there are no plans to back port it to NetBeans 5.5.

    Also unfortunately, Java DB doesn't have an ODBC driver - an issue I've already raised with the Java DB team :-). For now, to access Java DB, you need to use JRuby, which I cover in my previous post.

    Posted by: bleonard on April 15, 2007 at 08:42 AM

  • Great! Do you see similar performance for RoR on Windows? SEO

    Posted by: winrelocation on October 30, 2007 at 01:32 AM



Only logged in users may post comments. Login Here.


Powered by
Movable Type 3.01D
 Feed java.net RSS Feeds