<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Panscendo &#187; rubyamf</title>
	<atom:link href="http://panscendo.com/category/rubyamf/feed/" rel="self" type="application/rss+xml" />
	<link>http://panscendo.com</link>
	<description>Talks of nature and technology</description>
	<lastBuildDate>Tue, 14 Jun 2011 14:36:29 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>RubyAMF with Rails 2.0</title>
		<link>http://panscendo.com/rubyamf-with-rails-20/</link>
		<comments>http://panscendo.com/rubyamf-with-rails-20/#comments</comments>
		<pubDate>Mon, 17 Dec 2007 17:00:27 +0000</pubDate>
		<dc:creator>bryanc</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[rubyamf]]></category>

		<guid isPermaLink="false">http://panscendo.com/rubyamf-with-rails-20/</guid>
		<description><![CDATA[The RubyAMF blog was updated recently with information on RubyAMF support for Rails 2.0.  So far only one major bug and two minor ones have been found.  All three are being zapped as we speak.

Use of render :amf in a controller
Install script should modify initializers/mime_types.rb
rubyamf_config.rb should go in initializers

The use of render :amf [...]]]></description>
			<content:encoded><![CDATA[<p>The <a href="http://blog.rubyamf.org/">RubyAMF blog</a> was <a href="http://blog.rubyamf.org/?p=96">updated</a> recently with information on RubyAMF support for Rails 2.0.  So far only one major bug and two minor ones have been found.  All three are being zapped as we speak.</p>
<ul>
<li><a href="http://code.google.com/p/rubyamf/issues/detail?id=51">Use of render :amf in a controller</a></li>
<li><a href="http://code.google.com/p/rubyamf/issues/detail?id=53">Install script should modify initializers/mime_types.rb</a></li>
<li><a href="http://code.google.com/p/rubyamf/issues/detail?id=54">rubyamf_config.rb should go in initializers</a></li>
</ul>
<p>The use of render :amf was the bug that my RAMF tutorial attempted to address.  Tony Hillerson has committed a much more elegant fix so the tutorial will be updated once it becomes official.</p>
]]></content:encoded>
			<wfw:commentRss>http://panscendo.com/rubyamf-with-rails-20/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Free Flexible Rails chapter on RubyAMF</title>
		<link>http://panscendo.com/free-flexible-rails-chapter-on-rubyamf/</link>
		<comments>http://panscendo.com/free-flexible-rails-chapter-on-rubyamf/#comments</comments>
		<pubDate>Sun, 09 Dec 2007 23:01:34 +0000</pubDate>
		<dc:creator>bryanc</dc:creator>
				<category><![CDATA[flex]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[rubyamf]]></category>

		<guid isPermaLink="false">http://panscendo.com/free-flexible-rails-chapter-on-rubyamf/</guid>
		<description><![CDATA[Flexible Rails is a book written by Peter Armstrong that teaches the reader how to build RIAs with Flex 3 and Rails 2 by walking the reader through an in-depth tutorial.  Armstrong has been very active in the RubyAMF community and has made some great contributions.  His latest and greatest gift to us [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.flexiblerails.com/">Flexible Rails</a> is a book written by Peter Armstrong that teaches the reader how to build RIAs with Flex 3 and Rails 2 by walking the reader through an in-depth tutorial.  Armstrong has been very active in the RubyAMF community and has made some great contributions.  His latest and greatest gift to us all is a complete chapter, from his book, titled Iteration 11: Refactoring to RubyAMF.  You can download it as a pdf from his Manning Publication <a href="http://manning.com/armstrong/">site</a>.</p>
<p>Flexible Rails is available  now through the <a href="http://manning.com/armstrong/">Manning Early Access Program</a> and will be available in <a href="http://manning.com/armstrong/">print </a>sometime January 2008.</p>
<p>Thanks Peter!</p>
]]></content:encoded>
			<wfw:commentRss>http://panscendo.com/free-flexible-rails-chapter-on-rubyamf/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Rails 2.0 &#8211; No longer shy</title>
		<link>http://panscendo.com/rails-20-no-longer-shy/</link>
		<comments>http://panscendo.com/rails-20-no-longer-shy/#comments</comments>
		<pubDate>Sat, 08 Dec 2007 18:45:56 +0000</pubDate>
		<dc:creator>bryanc</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[rubyamf]]></category>

		<guid isPermaLink="false">http://panscendo.com/rails-20-no-longer-shy/</guid>
		<description><![CDATA[Rails 2.0 is finally polished and ready for the spotlight.  I&#8217;ll update the Beginner&#8217;s RAMF tutorial with any needed changes within the next few days.  I&#8217;ll also try to get the skinny on any of RAMF&#8217;S upcoming changes/bug fixes that need to be addressed for official Rails 2.0 support.
Rails 2.0 links:

Google cache of [...]]]></description>
			<content:encoded><![CDATA[<p>Rails 2.0 is finally polished and ready for the spotlight.  I&#8217;ll update the Beginner&#8217;s RAMF tutorial with any needed changes within the next few days.  I&#8217;ll also try to get the skinny on any of RAMF&#8217;S upcoming changes/bug fixes that need to be addressed for official Rails 2.0 support.</p>
<p>Rails 2.0 links:</p>
<ul>
<li><a href="http://72.14.253.104/search?q=cache:aFPxa2WWUo4J:weblog.rubyonrails.com/2007/12/7/rails-2-0-it-s-done+http://weblog.rubyonrails.com/2007/12/7/rails-2-0-it-s-done&amp;hl=en&amp;ct=clnk&amp;cd=1&amp;gl=us&amp;client=firefox-a">Google cache of official announcement</a></li>
<li><a href="http://weblog.rubyonrails.com/2007/12/7/rails-2-0-it-s-done">Official official announcement</a></li>
<li><a href="http://railscasts.com/">Railscasts </a>- Great screencasts covering some of the changes in rails 2.0</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://panscendo.com/rails-20-no-longer-shy/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Beginner&#8217;s Tutorial to RubyAMF with RESTful Rails</title>
		<link>http://panscendo.com/beginners-tutorial-to-rubyamf-with-restful-rails/</link>
		<comments>http://panscendo.com/beginners-tutorial-to-rubyamf-with-restful-rails/#comments</comments>
		<pubDate>Tue, 04 Dec 2007 02:03:32 +0000</pubDate>
		<dc:creator>bryanc</dc:creator>
				<category><![CDATA[actionscript 3.0]]></category>
		<category><![CDATA[flex]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[rubyamf]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://panscendo.com/?p=5</guid>
		<description><![CDATA[Note: This tutorial was originally posted at my deprecated blog Nature and Technology.  Please check back here for further updates.
RubyAMF is a flash remoting gateway that allows a Rails backend to communicate with a Flex frontend.  The marriage allows rapid development of rich internet applications. This tutorial goes over the basic steps of [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Note:</strong> This tutorial was originally posted at my deprecated blog <a href="http://natureandtech.blogspot.com/">Nature and Technology</a>.  Please check back here for further updates.</p>
<p><a href="http://blog.rubyamf.org/">RubyAMF</a> is a flash remoting gateway that allows a Rails backend to communicate with a Flex frontend.  The marriage allows rapid development of rich internet applications. This tutorial goes over the basic steps of creating a RESTful Rails project that has a HTML and Flex frontend and data persistence via MySQL database.</p>
<h1>Rails</h1>
<h2>Setting up the Rails Project</h2>
<p>Create a new rails project by first opening a command prompt and then changing the working directory to your rails project directory.  Once there type the following command to create a rails project called &#8220;rubyamf&#8221;</p>
<p><code>&gt; <strong>rails rubyamf</strong></code></p>
<p>Now that we have a project created we need to install RubyAMF by using the rails installer.  To do this you must first move into the rubyamf directory and then run the ruby plugin installer script</p>
<p><code> </code></p>
<pre>
&gt; <strong>cd rubyamf</strong>

rubyamf&gt; <strong>ruby script/plugin install http://rubyamf.googlecode.com/svn/trunk/rubyamf</strong></pre>
<p><em>Note: If you receive a error like this: &#8220;Missing the Rails 1.99.0 gem.  Please &#8216;gem install -v=1.99.0 rails&#8217;, update your RAILS_GEM_VERSION setting in config/environment.rb for the Rails version you do have installed, or comment out RAILS_GEM_VERSION to use the latest version installed.&#8221; then you just need to commet out the the line specified by the error.  Since Rails 2.0 is still being developed it isn&#8217;t actually 1.99.0 but 1.99.blah.</em></p>
<h2>Connecting Rails to your Database</h2>
<p>Since we want to be able to save our data we need to create a database to store said data.  Open up a command prompt again and, assuming MySQL is already running, type:</p>
<p><code> </code></p>
<pre>&gt; <strong>mysql -u root -p</strong>

Enter password:

mysql&gt; <strong>create database rubyamf;</strong></pre>
<p>Good, now we need to tell Rails how to communicate with the database we just created.  Open up the config/database.yml file and edit the text to look like this:</p>
<p><code> </code></p>
<pre>development:

 adapter: mysql

 endocing: utf8

 database: <strong>rubyamf</strong>

 username: root

 password: <strong>yourpassword</strong>

 host: localhost</pre>
<h2>Creating a REST controller</h2>
<p>We now have a Rails project that is able to talk to a database.  Cool!  Now what we need to do is create a controller that issues the commands.  Rails allows us to do this with a little beauty command called &#8220;scaffold_resource.&#8221;  When we run it we always follow it with an uppercase singular noun and a series of name value pairs.  The noun is the name of the Rails model, or the database table, and the name:value pairs are the names of the column in the table and their datatype.  Lets try it out; open up that command prompt once again, make the rubyamf directory the active dir and then issue the following command:</p>
<p><code>rubyamf&gt; <strong>ruby script/generate scaffold Message text:string</strong></code></p>
<p><em>Note: &#8220;scaffold_resource&#8221; has been changed to &#8220;scaffold&#8221; in Rails 2.0.</em></p>
<p>Among other things you now have two important files; messages_controller.rb which Flex and RubyAMF will communicate with, and a migrate file (called 001_create_messages.rb) that we will run to create the database table.</p>
<p>Lets do the latter right now. In the command prompt type this:</p>
<p><code>rubyamf&gt; <strong>rake db:migrate</strong><br />
</code></p>
<h2>Making Sure it all Works</h2>
<p>We&#8217;re basically finished with rails for now. But before we call it good lets just make sure that it is running smoothly (and so we can look in awe of what we just did).</p>
<p>Boot up your rails server:</p>
<p><code>rubyamf&gt; <strong>ruby script/server</strong></code></p>
<p>Now open up your favorite browser and make sure that RubyAMF is running by going to <a href="http://localhost:3000/rubyamf/gateway">http://localhost:3000/rubyamf/gateway</a>.  You should see something like the following image.</p>
<p><img src="http://brudert.googlepages.com/check_html_ui.gif" alt="Screenshot of RubyAMF Gateway up and running" /></p>
<p>If you do not get the above image and instead get prompted to download an AMF file you need to edit the app/controllers/rubyamf_controller.rb file.  Open it up and change:</p>
<p><code> </code></p>
<pre>amf_response = if request.env['CONTENT_TYPE'].to_s.match(/x-amf/)

    headers['Content-Type'] = "application/x-amf"

    RailsGateway.new.service(request.raw_post) #send the raw data throught the rubyamf gateway and create the response

  else

    welcome_screen_html # load in some stub html

  end

send_data(amf_response, :type =&gt; 'application/x-amf')</pre>
<p>To:</p>
<p><code> </code></p>
<pre>amf_response = if request.env['CONTENT_TYPE'].to_s.match(/x-amf/)

    <strong>content_type  = "application/x-amf"</strong>

    RailsGateway.new.service(request.raw_post) #send the raw data throught the rubyamf gateway and create the response

  else

    <strong>content_type = "text/html"</strong>

   welcome_screen_html # load in some stub html

  end

<strong>send_data(amf_response, :type =&gt; content_type, :disposition=&gt;'inline')</strong></pre>
<p><em>Note: If you use the <a href="http://blog.rubyamf.org/?p=88#comment-497">rubyamf controller fix</a> suggested on the <a href="http://blog.rubyamf.org/">RAMF blog</a> it will brake your application (thanks goes to Quest4 for <a href="http://natureandtech.blogspot.com/2007/10/beginners-tutorial-to-rubyamf-with.html#comment-5604273395245235170">figuring</a> this one out).  The above code is not official so use it at your own risk.</em></p>
<p>Now make sure our Messages controller is working by pointing your browser to <a href="http://localhost:3000/messages">http://localhost:3000/messages</a> and witnessing this:</p>
<p><img src="http://brudert.googlepages.com/check_messages.gif" alt="Screenshot of message controller" /></p>
<p>So far so good. Now what we need to do is to add some data into the database so our Flex app has something to retrieve.  Lets do that by clicking the &#8220;New Message&#8221; link at http://localhost:3000/messages, typing a short message (this tutorial uses &#8220;Hello World&#8221;), and press the &#8220;Create&#8221; button.  *Bam* you just added a new Message to the database.</p>
<p>Enough of Rails, lets dive into Flex</p>
<h1>Flex</h1>
<h2>Setting up the Flex Project</h2>
<p>Boot up Adobe Flex and create a new project. I named mine rubyamf for consistency but you could name it something else (like planctomyces). Click the &#8220;Next&#8221; button, not the &#8220;Finish&#8221; button.  Set the output folder to the &#8220;bin&#8221; dir (you&#8217;ll probably have to create this) in the &#8220;public&#8221; dir of your rails project.  That is, <strong>\rubyamf\public\bin</strong>.  Press &#8220;Next.&#8221; Now make sure that your output folder URL is set to: <strong>http://localhost:3000/bin</strong>.  Press &#8220;Finish.&#8221; You now have a shiny new Flex project.</p>
<h2>Adding services-config.xml</h2>
<p>We need to create an XML file that will point your Flex project in the direction of your Rails project.  This is called the &#8220;services-config.xml&#8221; file and it needs to be placed in the same folder as your MXML file.  Create a new file via <strong>File &gt; New &gt; File</strong> and name it &#8220;services-config.xml&#8221;</p>
<p>Now for the code.  Open up &#8220;services-config.xml&#8221; and add this code:</p>
<p><code> </code></p>
<pre>&lt;?xml version="1.0" encoding="UTF-8"?&gt;

 &lt;services-config&gt;

  &lt;services&gt;

   &lt;service id="rubyamf-flashremoting-service" class="flex.messaging.services.RemotingService" messageTypes="flex.messaging.messages.RemotingMessage"&gt;

    &lt;destination id="rubyamf"&gt;

     &lt;channels&gt;

      &lt;channel ref="rubyamf"/&gt;

     &lt;/channels&gt;

     &lt;properties&gt;

      &lt;source&gt;*&lt;/source&gt;

     &lt;/properties&gt;

    &lt;/destination&gt;

   &lt;/service&gt;

  &lt;/services&gt;

  &lt;channels&gt;

   &lt;channel-definition id="rubyamf" class="mx.messaging.channels.AMFChannel"&gt;

    &lt;endpoint uri="http://localhost:3000/rubyamf/gateway" class="flex.messaging.endpoints.AMFEndpoint"/&gt;

   &lt;/channel-definition&gt;

  &lt;/channels&gt;

 &lt;/services-config&gt;</pre>
<p>Now we tell Flex to include &#8220;services-config.xml&#8221; when it compiles the application.  To do this we need to add a command to the flex compiler.  Do this by <strong>Project &gt; Properties &gt; Flex Compiler</strong> and adding <strong>-services &#8220;services-config.xml&#8221;</strong> to the &#8220;Additional compiler arguments&#8221; field.</p>
<p><img src="http://brudert.googlepages.com/compiler_options.gif" alt="Screenshot showing additional compiler arguments field" /></p>
<h2>Creating the UI</h2>
<p>Now the fun part.  Here&#8217;s the Flex UI code to paste into the MXML file:</p>
<p><code> </code></p>
<pre>&lt;?xml version="1.0" encoding="utf-8"?&gt;

 &lt;mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical"&gt;

  &lt;mx:TextArea id="resultTxt"

   width="80%" height="30%" /&gt;

  &lt;mx:Button id="getMessage"

   label="Get Messages" /&gt;

  &lt;mx:TextArea id="createTxt"

   width="80%" height="30%" /&gt;

  &lt;mx:Button id="createMessage"

   label="Create Message" /&gt;

 &lt;/mx:Application&gt;</pre>
<p>The above should look something like this:</p>
<p><img src="http://brudert.googlepages.com/flex_ui.gif" alt="Screenshot of flex ui" /></p>
<p>The above is pretty and all but it&#8217;s like a mannequin; looks good but it has no function.  Lets give it a purpose and turn it into a real live lady.  We&#8217;ll do this by adding the RemoteObject code.</p>
<p>Between the &lt;mx:Application&gt; and &lt;mx:TextArea /&gt; tags add this:</p>
<p><code> </code></p>
<pre> &lt;mx:Script&gt;

  &lt;![CDATA[

   import mx.rpc.events.ResultEvent;

   import mx.rpc.events.FaultEvent;

   import mx.rpc.Fault;   private function onFault(e:FaultEvent):void

   {

    resultTxt.text = e.fault.faultString;

   }

   private function onResult(e:ResultEvent):void

   {

    resultTxt.text = e.message.toString();

   }

  ]]&gt;

 &lt;/mx:Script&gt;

&lt;mx:RemoteObject id="messageService" fault="onFault(event)"

  source="MessagesController" destination="rubyamf"&gt;

  &lt;mx:method name="index" result="onResult(event)" /&gt;

  &lt;mx:method name="create" result="onResult(event)" /&gt;

 &lt;/mx:RemoteObject&gt;</pre>
<ul>
<li><strong>RemoteObject</strong> is where the magic occurs.  This particular instance we chose to call <strong>id=&#8221;messageService&#8221;</strong></li>
<li><strong>source=&#8221;MessagesController&#8221;</strong> is the name of the rails controller we want to communicate with.  The actual name needs to be exactly the same as the ruby class name (open up app/controllers/messages_controller.rb)</li>
<li><strong>destination=&#8221;rubyamf&#8221;</strong> maps to the channel-definition in the services-config.xml file we created earlier (which then points Flex to the rubyamf remoting endpoint).</li>
<li>The two <strong>&lt;mx:method /&gt;</strong> tags map to two of the methods in the MessagesController class.</li>
</ul>
<p>To call our methods we&#8217;ll update the &#8220;click&#8221; event handlers of the two buttons in our UI. Add <strong>click=&#8221;messageService.index.send();&#8221;</strong> to the &#8220;getMessage&#8221; button and <strong>click=&#8221;messageService.create.send({text: createTxt.text});&#8221;</strong> to the &#8220;createMessage&#8221; button.</p>
<p><code> </code></p>
<pre> &lt;mx:Button id="getMessage"

  label="Get Messages"

  click="messageService.index.send();" /&gt; &lt;mx:Button id="createMessage"

  label="Create Message"

  click="messageService.create.send({text: createTxt.text});" /&gt;</pre>
<h1>Back to Rails</h1>
<h2>Tweaking messages_controller.rb</h2>
<p>We&#8217;re almost finished. All we have to do now is explain to our rails controller about AMF. We&#8217;ll be polite and speak it&#8217;s native language; ruby.  Open up <strong>app/controllers/messages_controller.rb</strong> and add <strong>&#8220;format.amf { render :amf =&gt; @messages }&#8221;</strong> to the <strong>respond_to</strong> block of the <strong>index</strong> method.</p>
<p><code> </code></p>
<pre> def index

     @messages = Message.find(:all)     respond_to do |format|

       format.html # index.rhtml

       format.xml  { render <img src='http://panscendo.com/wp-includes/images/smilies/icon_mad.gif' alt=':x' class='wp-smiley' /> ml =&gt; @messages.to_xml }

       format.amf { render :amf =&gt; @messages }

     end

 end</pre>
<p>The <strong>respond_to</strong> block tells our controller to act differently when different mediums are attempting to work with it.  If a browser calls the <strong>index</strong> method the controller will spit out HTML but now if the Flash Player requests something the controller will spit out AMF.  Perfect!</p>
<p>Updating the <strong>create</strong> method is a bit trickier.  We add an <strong>if</strong> statement to check if AMF was sent, and if so, do some tricky stuff.</p>
<p><code> </code></p>
<pre> def create

  if is_amf

   @message = Message.new({:text =&gt; params[0][:text]})

  else

   @message = Message.new(params[:message])

  end

 ...</pre>
<p><em>Note: params[0][:text] was <a href="http://natureandtech.blogspot.com/2007/10/beginners-tutorial-to-rubyamf-with.html#comment-4536511138216079615">suggested</a> by Peter Armstrong &#8211; thanks!</em></p>
<p>Then we add some code to the respond_to block that tells the controller to speak AMF if it&#8217;s talking to the flash player.</p>
<p><code> </code></p>
<pre> ...

  respond_to do |format|

    if @message.save

         flash[:notice] = 'Message was successfully created.'

         format.html { redirect_to message_url(@message) }

         format.xml  { head :created, :location =&gt; message_url(@message) }

   format.amf  { render :amf =&gt; "Message Saved" }

       else

         format.html { render :action =&gt; "new" }

         format.xml  { render <img src='http://panscendo.com/wp-includes/images/smilies/icon_mad.gif' alt=':x' class='wp-smiley' /> ml =&gt; @message.errors.to_xml }

   format.amf  { render :amf =&gt; @message.errors }

       end

     end

   end</pre>
<p>Whew!  That&#8217;s it.  We can test the app now.</p>
<h2>Testing&#8230; (in awe)</h2>
<p>First we need to start our server (or restart it).</p>
<p><code>rubyamf&gt; <strong>ruby script/server</strong></code></p>
<p>Compile and run your Flex project.  It should be running from the URL &#8220;http://localhost:3000/bin/rubyamf.html.&#8221; Click on &#8220;Get Messages&#8221; and you should see something like this:</p>
<p><img src="http://brudert.googlepages.com/check_get_messages.gif" alt="checking if get-messages works" /></p>
<p>Type a message into the second text area (&#8220;We received data from RubyAMF, can we send data to it?&#8221;).  Press the button and you should see:</p>
<p><img src="http://brudert.googlepages.com/check_create_message.gif" alt="checking if create-message works" /></p>
<h1>Finished!</h1>
<p>Yee-haw! By using the powers of RubyAMF we have just grabbed data from a database and written some right back at speeds <a href="http://blog.vixiom.com/2007/07/19/flex-rubyamf-screencasts/">much faster</a> than XML or JSON. Plus, we still get a HTML front end for those types that fear flash.</p>
]]></content:encoded>
			<wfw:commentRss>http://panscendo.com/beginners-tutorial-to-rubyamf-with-restful-rails/feed/</wfw:commentRss>
		<slash:comments>19</slash:comments>
		</item>
	</channel>
</rss>

