<?xml version="1.0" encoding="UTF-8"?>
<posts type="array">
  <post>
    <body>As I've "previously mentioned":http://www.experimeme.net/rubyamf-currently-breaks-rspec-tests, RubyAMF gives you @render:amf@ so you can send controller responses as binary AMF streams to Flash / Flex applications (also known as Flash remoting).

Setting it up for rails is reasonably straightforward. You just need to @script/install http://rubyamf.googlecode.com/svn/trunk/rubyamf@ to install the plugin. If you're developing locally you'll want to restart your webserver, and then you should be able to browse to http://localhost:3000/rubyamf_gateway/ which will return an http response with a logo of RubyAMF.

Once that's done the class mappings need to be specified, so that (for instance) a Tag class in ActionScript returned by a client swf is automatically deserialised into the appropriate Tag class within the Rails application.

Over a few posts I'm going to demonstrate putting together a Flex-based tag cloud which uses RubyAMF, so the mapping (which is defined in @config/rubyamf_config.rb@) would be this:

&lt;code lang="ruby"&gt;
ClassMappings.register(:actionscript =&gt; 'Tag', :ruby =&gt; 'Tag', :type =&gt; 'active_record',
:attributes =&gt; ["id", "name", "count"])
&lt;/code&gt;

(There's plenty of examples in the config file along with other options worth looking at.)

Once that's defined you'll want to specify a controller method which returns your tag cloud data and also responds to AMF requests. As I "mentioned earlier":http://www.experimeme.net/adding-tagging I'm using "acts_as_taggable_on_steroids":http://agilewebdevelopment.com/plugins/acts_as_taggable_on_steroids at the moment, and this plugin gives me a method which returns all tags and their counts, so the method (defined in my @posts_controller.rb@ file) is as simple as this:
&lt;code lang="ruby"&gt;
def tag_counts
	@tags = Post.tag_counts
	respond to do |format|
		format.html # If you'd like to do something in html
		format.amf { render:amf =&gt; @tags }
	end
end
&lt;/code&gt;

At this point you'll have an AMF gateway and a method which will return a complex datatype serialised as AMF. The next step is to build a Rich Client in Flex to consume this service.</body>
    <created-at type="datetime">2008-11-30T17:31:46Z</created-at>
    <ham-comments-count type="integer">0</ham-comments-count>
    <id type="integer">26</id>
    <permalink>setting-up-rubyamf-for-flash-and-flex</permalink>
    <title>Setting up RubyAMF for Flash and Flex</title>
    <updated-at type="datetime">2008-12-08T00:06:08Z</updated-at>
  </post>
</posts>
