Let’s prepare the system to create a reactive application.
Install reactive
Reactive is hosted on RubyForge, so using the gem command is all you need. Note that you’ll need rubygems 1.1.0 or later.
Because Reactive is very modular, we must choose which plugins to install, we want:
- The core system: reactive-core
- We are developers, so we want generators, rake tasks, etc… : reactive-dev
- A dispatcher that handles MVC: reactive-mvc
- reactive-mvc doesn’t impose an ORM, so choose one: reactive-activerecord
- A way to expose data to the user (and get requests from it) : reactive-wx
Go for it:
sudo gem install reactive-core
sudo gem install reactive-dev
sudo gem install reactive-mvc
sudo gem install reactive-activerecord
sudo gem install reactive-wx
Done! Check if reactive is here:
reactive
And the usage is printed on your terminal.
Create the application
Tell reactive to create our app and choose all the plugins we use:
reactive books reactive-mvc reactive-activerecord reactive-wx
Your app is ready to run, let’s try it.
cd books
script/run
Okay, the window is minimalistic, but it is ready to host your application.
Add a resource
Our books application will simply handle books, so we need a Book resource:
script/generate resource book title:string isbn:string
Now setup the database:
rake db:create
rake db:migrate
Let’s add a validation in the model (app/models/book.rb)
class Book < ActiveRecord::Base
validates_numericality_of :isbn
end
Code the views
The big part is now to fill the views. Our output handler (reactive-wx) expects the response body to be ruby code using the wxRuby library. So we must fill the views (index, new, create, …) with that ruby code.
This part is time consuming, the UI part of an application always is.
I’ll not show the details here, please download the books application and inspect the views. Choose either the complete application or only the new files at this point of the howto.
Currently Reactive definitively needs documentation. This task is planned for the next months.
Note also that I’m currently working on a scaffold system inspired by ActiveScaffold.