AgileDevelopmentOfThePluginPortal

Agile Development of the Plugin Portal Demo (10 Minutes)

Description

This Ruby on Rails demo, through a series of iterations, gets a basic application for managing the Plugin Portal, up and running. This demo uses Rails 1.2.5, which is the version that ships with NetBeans 6.0. For Rails 2.0 and NetBeans 6.1, please use this version.

Product Versions Supported

NetBeans 6.0

Points to Hit

It's easy to be agile with Rails, especially because of the following features this demo illustrate:
  • Database Migrations
  • Instant Feedback Loop
  • Scaffolding
  • Easy Validation

Demo Prep

The demo steps assume you are using CRuby and MySQL. CRuby was chosen because the following debugging demo does not yet work well on JRuby. If necessary, the steps could be augmented to work with JRuby (basically the database connectivity).

  1. Install native Ruby (CRuby) from http://www.ruby-lang.org/
  2. Install MySQL Database Server Community Edition from http://dev.mysql.com/
  3. Configure NetBeans to use CRuby (Tools > Options > Misc > Ruby)
  4. Use the Gem Manager to install Rails (Tools > Ruby Gems > New Gems
  5. Add the MySQL JDBC Driver to NetBeans http://dev.mysql.com/usingmysql/java/
  6. Create a connection to the mysql database (jdbc:mysql://localhost/mysql). From this connection you can easily execute commands to create other databases.

Gotchas

None known at this point

Demo

Iteration 1: Get Something Running

  • Create a new Ruby on Rails Application named plugin_portal
  • Create a new database named plugin_portal_development
  create database plugin_portal_development;
  • Edit the database.yml file (under Configuration) and specify the MySql username/password on lines 17 and 18. These should be the same as the username/password used to create the database.
  • Create a model named Plugin with 3 initial columns: name, description and plugin_url. (Right-click the project and select Generate. Select model and set the arguments to Plugin name:string description:text plugin_url:string).
  • Review the Output window for what was created: the model class, a unit test, a test fixture and a migration. This presentation doesn't have time to get into testing.
  • Open and review the 001_create_plugins migration that was created as part of the model generation.
  • Right-click the project choose Migrate Database > To Current Version
  • Generate a controller to work with the data table. Generate > Controller > PluginPortal
  • In the PluginPortalController, which is now open in the Editor add the following. A Rails scaffold is an dynamically generated (remember metaprogramming) framework for manipulating a model:
      scaffold :plugin

Iteration 2: Add a Missing Column

We forgot to include the plugin's price

  • Generate a Migration named AddPrice
  • Add the following to the self.up method using the mcol template (mcol <tab>):
          add_column :plugins, :price, :decimal, :precision => 8, :scale => 2, :default => 0
  • Add the following to the self.down method (for the demo, I created the following code template mcolr - :${1 default="key"} => "${2 default="value"}"${4 default=", "
          remove_column :plugins, :price
  • Save and migrate again to the current version.
  • Return to the browser and refresh the page (this is the instant feedback loop developers love)
  • Just for kicks, migrate back to version 1 and refresh the browser page.
  • Migrate back to the current version for the next step

Iteration 3: Validate!

  1. Switch to the plug-in model and type vp<tab> which expands to validates_presence_of and add :name, :description.
      validates_presence_of :name, :description, :plugin_url
  • Add one for price as well (this is no template for this - yet. For the demo, I create the following template vn - validates_numericality_of :${1 default="attribute"})
      validates_numericality_of :price
  • Similarly we could validate the price is not negative and that the format of the url is correct, but this is beyond the scope of this demo.
  • Test

Interation 4: Generate the Views So They Can Be Modified

Currently, the scaffolding is auto-generating our views using metaprogramming. Since we ultimately want to customize the look of our application, let's generate the view and controller code for our app.

  • Generate a scaffold, setting the Model Name to plugin and the Controller Name to PluginPortal. Be sure to select the Overwrite option as the PluginPortal controller already exists.
  • The application will behave the same, but all of the code that was being dynamically generated for us is now part of our controller and the views have also been generated.
  • Show the generated code in the PluginPortalContoller as well as the views that were created.

Next Steps

Debugging the Plugin Portal

Demo Cleanup

These are the necessary steps to take in order to successfully run the demo again on the same machine.

  1. Migrate the database to version 0.
  2. Delete the plugin_portal project
  3. Delete the plugin_portal datbase
  drop database plugin_portal_development;
Not logged in. Log in, Register

By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo