views:

709

answers:

7

I'm looking at Rails development as a backend to a Flex application and am trying to figure out the communication layer between the Rails app and the Flash Player. All of the things I am finding suggest using SOAP web services to communicate.

However, Flash supports AMF which is nice and fast (and native). Is there any way of communicating over AMF from a Rails app, whilst supporting all the "nice" things about AMF (automatic type conversion, data push etc).

A: 

There's a Rails plugin called WebORB for Ruby on Rails which uses remoting with AMF.

Kristian J.
+2  A: 

There is WebORB or RubyAMF which you can use to respond in AMF from Rails, the approaches are a bit different for each one so it depends on your needs. RubyAMF is discussed in the closing chapters of the Flexible Rails eBook which is a good resource on using Rails with Flex.

DEfusion
+1  A: 

You wouldn't use SOAP web services but rather 'native' REST web services, which are native in Rails. The book quoted by DEFusion above is actually about that: how to use a FLEX client as the front-end of a Rails application using REST (meaning XML).

The AMF protocol has primarily been built by Adobe as a binary protocol to allow FLEX front-ends to talk to CodeFusion and of course Java server applications. It's not free, apart from using Adobe's BlazeDS for which you actually won't have much support. And then of course, you'll have to choose a plugin capable of talking to BlazeDS using the AMF protocol (again, see DEfusion's posts) and rely on it.

You'd be surprised how well direct Flex to Rails via REST works, plus you don't have to rely on third-parties. I'd recommend you try it.

Hope this helps

Rollo Tomazzi
+2  A: 

I'm in the middle of writing a rails/flex application and we're moving to using a JSON communication within the REST framework. Simple HTTP requests from the Flex side handling JSON responses seemed like the best way to decouple the client and server. XML is just as easy.

For what it's worth, we're using the PureMVC framework on the flex side as well, keeping the responses in a client-side model.

Glenn
+1  A: 

Go with RubyAMF if you want an MVC style interaction with contollers that can respond to/generate AMF.

Use WebOrb for any other style, including direct access to model objects.

A: 

You can use WebORB or RubyAMF, or just plain XML - Rails is pretty smart when it comes to XML, with a few gotchas here and there.

We use XML to speak between our Rails apps and our Flex web application, almost exclusively. It's pretty simple.

For retrieving data from your Rails app, just create an HTTPService with result_type of e4x, and call your url. In your rails controller, do something like:

def people
  render :xml => Person.all.to_xml
end

Sometimes, Rails will add the tag to the end. If this happens, change your controller to:

def people
  render :xml => Person.all.to_xml.target!
end

If you want to send data to your Rails app, it's just as easy..

<mx:HTTPService id="theservice" url="http://localhost:3000/svc/add_person" method="POST">
 <mx:request>
  <person>
   <first>Firstname</first>
   <last>Lastname</last>
  </person>
 </request>
</HTTPService>

and in your controller:

def add_person
  p=Person.create(params[:person])
  render :xml => {:result => "Success"}.to_xml.target!
end
  • Kevin
Kevin Marvin
A: 

I've built apps using all three methods (WebOrb, RubyAMF, REST)...

WebOrb for Rails is pretty much dead, it hasn't been updated in quite sometime. That said I was able to create a bit of Flex/Ruby magic that makes Flex access to Rails' model objects transparent... if you're interested I'll dig it up and send it to you.

RubyAMF is nice, but not as Flexible (ha!) as WebOrb.

REST returning JSON is a snap, and if I have to build another one of these (I hope not) that's what I'll continue to use.

YMMV.

Mike