I just committed the code to enable Rails controller integration in SWX Ruby. This is big news folks. For those of you wishing to very easily add SWX capabilities to an existing Rails app or those wishing for tighter integration between SWX Ruby and their existing controller setup, your wish has been granted.
Simply call render :swx => ‘my swx data’ from a Rails controller and SWX Ruby will send back a SWX file containing ‘my swx data’.
The SWX Ruby plugin also registers a MIME type for SWX files. This enables you to serve up your SWX data in RESTful style:
# in config/routes.rb
ActionController::Routing::Routes.draw do |map|
map.connect '/restful.:format', :controller => 'Restful'
map.connect '/restful', :controller => 'Restful'
end
# in app/controllers/restful_controller.rb
class RestfulController
def index
respond_to do |format|
format.html { render :text => 'not a swx request' }
format.swx { render :swx => 'a swx request' }
end
end
end
With the preceding code in your app, pull up http://localhost:3000/restful in a browser. You’ll see ‘not a swx request’. Then open Flash, place an empty MovieClip on stage with an instance name of ‘loader’, and place the following ActionScript in frame 1:
loader.debug = true;
loader.loadMovie("http://localhost:3000/restful.swx", "GET");
function onEnterFrame() {
trace(loader.result);
}
Preview the Flash movie and the Output panel will begin tracing ‘a swx request’.
So when can I play with this?
This is checked in to trunk right now. script/plugin install http://swxruby.rubyforge.org/svn/trunk/
I’m planning on making a beta release of SWX Ruby by the end of the month which will include this new feature.
Note: In my recent testing, the install.rb script doesn’t execute when installing the plugin from trunk. Please let me know if you exeperience this issue and I’ll look into it further. A temporary workaround is to execute the install script manually:
$ script/plugin install http://swxruby.rubyforge.org/svn/trunk/
$ ruby vendor/plugins/trunk/install.rb
Update
This functionality is now available in the 0.5 release.