Getting Flex and Rails talking nicely with AMF

Posted by Neil on June 02, 2008

As a ColdFusion developer, integration with Flex is a very easy thing to do. ColdFusion understands Flex, and Flex understands ColdFusion. But what if we want to use another tool? What if we want to use the super-productive Ruby on Rails to build our backend? Well, thanks to the MidnightCoders that's now nice and easy to integrate with thanks to their WebOrb Product (which is free of charge thankfully).

So, how is it done? Well, let's walk you through it:

First up, check you have Ruby and Rails installed:

rails --version

If you get back a response giving you a version number, you're good to go. If not, consult the Rails documentation. Now let's create a rails app:

rails myrailsapp

...and install WebORB into it...

cd myrailsapp

ruby script/plugin install http://themidnightcoders.net:8089/svn/weborb

Easy so far? OK, Well let's take a look at it:

ruby script/server

Browse to http://localhost:3000/examples/main.html and you should be presented with a testsuite for your app and it's WebORB install. Easy.

So, what does this mean for you from the Flex point of view?

Well, WebORB basically pretends to be Flex Data Services, thus making the configuration nice and easy for you. Your root folder becomes your rails app config folder (myrailsapp/config) and the root URL is your webORB controller (http://localhost:3000/weborb).

For the output side of things, you should output your flex content to the /public folder of your flex app (/public/flex for instance), and point the URL to that same location (http://localhost:3000/flex).

Once you've done this you can go through the normal steps as you would with any FDS application. Setting up the destination/source in your remoting-config.xml etc. Once you're done, you're done. You can now talk to Rails as you would a CF application.

For example, Flex application declares a remote object using the RemoteObject API (for a getComputerInfo method):

[The requested file http://neilmiddleton.com/Mods/http://neilmiddleton.com/Mods/2008/06/ra ils_amf_sample_1.txt could not be found]

When a user clicks the 'Get Computer Info' button, the following function executes a remote method invocation:

[The requested file http://neilmiddleton.com/Mods/http://neilmiddleton.com/Mods/2008/06/ra ils_amf_sample_2.txt could not be found]

When an invocation response is available, Flex invokes a response handler specified in the tag. The response handler in the example, populates the text fields with the data available in the returned object:

[The requested file http://neilmiddleton.com/Mods/http://neilmiddleton.com/Mods/2008/06/ra ils_amf_sample_3.txt could not be found]

The source code for the server-side rail as object is below:

[The requested file http://neilmiddleton.com/Mods/http://neilmiddleton.com/Mods/2008/06/ra ils_amf_sample_4.txt could not be found]

and that's pretty much it. You can now do what you want with Flex and Rails.

Trackbacks

Use this link to trackback from your own site.

Comments

Leave a response

  1. Daniel Mon, 02 Jun 2008 16:48:12 EDT

    I understood that WebORB was a stagnant project at the moment, and that RubyAMF was the preferred AMF choice for Ruby/Rails apps. Any thoughts?

  2. Neil Mon, 02 Jun 2008 16:58:46 EDT

    @Daniel Certainly appears that way, WebORB hasn’t received any commits for a good six months or so, whereas I am aware that RubyAMF is under a lot more active development (RubyAMF v1.6 only came out a couple of weeks back).

    I hope to cover a RubyAMF walkthrough sometime soon to back this article up.

  3. [...] и това е хубав много нея. Сега можете да направите това, което искате с Flex и Ограда. Оригинална статия от Neil Middleton. [...]

Comments