|
|
GWT on Rails
GWT on Rails integrates GWT client side compiled JavaScript development with Rails REST web services by providing four things:
- A GWT client generator.
- A GWT model generator.
- An ActiveRecord extension to keep GWT models in sync with ActiveRecord models and migrations.
- The GWT-REST module.
Installation
script/plugin install http://gwt-on-rails.googlecode.com/svn/trunk/gwt_on_rails
Using the Client Generator and Rake Support
To build a JavaScript REST client for your app using GWT, do the following:
- Install the JSON Request plugin from Labnotes to make your life easier.
- Generate the client, passing along the name and the location of your GWT libs:
- Compile it:
- Test it in "Hosted Mode" (see GWT docs for more on this):
script/generate gwt_client dashboard /Users/jdoe/java_libs/gwt-mac-1.4.61
rake dashboard:compile
rake dashboard:hosted
From this point forward, you can click the "Refresh" button in the Hosted Mode browser to recompile updated Java code.
The above steps will generate a "gwt" tree under RAILS_ROOT/app that will house all GWT clients for your Rails application. Compiled JavaScript output will appear under public/gwt and follows the Java/GWT convention of requiring a package for each class (i.e. "dashboard" is housed in "dashboard.Dashboard").
Using Migrations to Manage GWT Client Resources/Models
To use an ActiveRecord "Project" model on the client side, do the following:
- Generate the GWT model/resource:
- Sync it:
script/generate gwt_resource Project dashboard
rake db:migrate
The above will produce two classes, Project.java and ProjectBase.java in the "resources" package of your GWT client tree. ProjectBase matches your ActiveRecord model and will be regenerated with each migration. Project extends ProjectBase and can thus be used to hold custom code.
Status
This has been tested with Rails 2.0.1, all of its abstract field types, MySQL, and a Mac with GWT 1.4.61 (a build with a fix for Leopard) and GWT-REST 0.1 (bundled). There may be issues with other configurations, especially on Windows where GWT's compilation scripts may need some tweaks for pure Windows (i.e. no cygwin) environments.
