← Back to the blog

Getting Flex and Rails talking nicely with AMF

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):

[viewcode] src=“2008/06/rails_amf_sample_1.txt” geshi=actionscript[/viewcode]

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

[viewcode] src=“2008/06/rails_amf_sample_2.txt” geshi=actionscript[/viewcode]

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:

[viewcode] src=“2008/06/rails_amf_sample_3.txt” geshi=actionscript[/viewcode]

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

[viewcode] src=“2008/06/rails_amf_sample_4.txt” geshi=Ruby[/viewcode]

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

Posted by Neil Middleton on 02 Jun 2008

blog comments powered by Disqus

From our portfolio

Jo's Trust
Website
JoTrust-Thumbnail
Charis Grants
Application
charis_thumbnail
iMoneymanager
Application
imoneymanager_small
www.flickr.com

Archives

From our blog

We’re looking for Ruby on Rails (RoR) developers to join our team!

Posted by Niklas Richardson on 12 Apr 2012

Monochrome are looking for a couple of enthusiastic Ruby on Rails developers to join the team – Both Lead and Junior/graduate roles. You don’t need to have years of Ruby on Rails...

The need for applications just keeps on growing

Posted by Adrian Munn on 24 May 2011

After 12 years in the industry experience has always told us to adapt and modify strategies in your business in order to survive and thrive. Monochrome are not adverse to taking on new challenges...

Places we would like to go...

Posted by Neil Middleton on 21 Jan 2011

Quite often in the office we will end up having a conversation about some particular company, that does something on a massive scale, and has a relevance to either technology or some sort of large...