A Flex application can "talk" to a Rails app using SOAP or standard HTTP requests. For the later, a Rails app can offer a URL at which a Flex application can make an mx:HTTPService request.

There is surprisingly little out there on the web describing how to do this, and things to do to avoid intractable security problems. Hopefully, some of you will find this post useful in this area.

Some suggestions for how to deploy a Rails application in way that avoid Flash cross domain security errors.

(1) Set up your Rails application, as always, to accept HTTP requests at a typical Rails URL, e.g., http://www.mydomain.com/items/list. In this case, the items controller makes a list action available at items/list (note that I'm using standard, "old-style" controller/action routes here; this can be just as easily done using RESTful routes, adhering to the same principles for specifying URL's, described below).

For example, the items controller list action can include code to "find" all records in the database, store in an array, and return the result as xml:

item_list = Item.find(:all, :order => "id ASC");
render :xml => item_list.to_xml and return if item_list

(2) Your Flex application might have an mx:HTTPService component that consumes makes the request at the specified URL:

HTTPService id="item_list_service" useProxy="false" url="items/list" result="itemListResultHandler(event)" fault="serviceFaultHandler(event)" method="GET"

One important thing to note: use a relative url (items/list), NOT a fully qualified, absolute url (http://www.mydomain.com/items/list or even /items/list) for your Rails service. If you use an absolute url url the Flash player will take your request as cross domain, and likely generate a cross domain security error! Now you could use a cross domain policy file (crossdomain.xml) at the root of your Rails application (in the public directory), but cross domain policy problems are notoriously difficult to resolve. If you aren't making a cross domain request, then why invite possible trouble? Yes, your Flex and Rails applications are on the same domain, but that's how the Flash player sees it.

If you are new to working with Flex on Rails, I hope you find the above useful. I do not offer comments on this blog, but if you have anything to contribute, contact me via and I would be happy to post your comments (or corrections!) and offer whatever credit you wish to receive.