<?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>DEfusion.org.uk &#187; Rails</title>
	<atom:link href="http://www.defusion.org.uk/archives/category/web-development/ruby/rails/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.defusion.org.uk</link>
	<description>I too will force my opinions on you</description>
	<lastBuildDate>Mon, 04 Jul 2011 19:28:08 +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>Quick Link: Dead simple task scheduling in Rails</title>
		<link>http://www.defusion.org.uk/archives/2009/02/14/quick-link-dead-simple-task-scheduling-in-rails/</link>
		<comments>http://www.defusion.org.uk/archives/2009/02/14/quick-link-dead-simple-task-scheduling-in-rails/#comments</comments>
		<pubDate>Sat, 14 Feb 2009 11:23:04 +0000</pubDate>
		<dc:creator>Dave</dc:creator>
				<category><![CDATA[Outer Monologue]]></category>
		<category><![CDATA[Quick Link]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://www.defusion.org.uk/archives/2009/02/14/quick-link-dead-simple-task-scheduling-in-rails/</guid>
		<description><![CDATA[I&#8217;ve just come across this post on dead simple task scheduling in Rails by the guys at intridea. It looks like a really nifty way to setup scheduled tasks in your Rails app, previously I had my tasks in rake files which I would then hit with cron. 
While that is working perfectly adequately for [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve just come across this post on <a href="http://www.intridea.com/posts/dead-simple-task-scheduling-in-rails">dead simple task scheduling in Rails</a> by the guys at <a href="http://www.intridea.com/">intridea</a>. It looks like a really nifty way to setup scheduled tasks in your Rails app, previously I had my tasks in rake files which I would then hit with cron. </p>
<p>While that is working perfectly adequately for my current setup it does have one downside, when I setup a new server I will have to setup the crontab file too. With <a href="http://www.intridea.com/posts/dead-simple-task-scheduling-in-rails">this method</a> when I deploy my app my scheduled tasks would get deployed and be running out of the box. Nice.</p>]]></content:encoded>
			<wfw:commentRss>http://www.defusion.org.uk/archives/2009/02/14/quick-link-dead-simple-task-scheduling-in-rails/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Testing That An Observer Is Registered In Rails With RSpec</title>
		<link>http://www.defusion.org.uk/archives/2008/07/23/testing-that-an-observer-is-registered-in-rails-with-rspec/</link>
		<comments>http://www.defusion.org.uk/archives/2008/07/23/testing-that-an-observer-is-registered-in-rails-with-rspec/#comments</comments>
		<pubDate>Wed, 23 Jul 2008 14:32:15 +0000</pubDate>
		<dc:creator>Dave</dc:creator>
				<category><![CDATA[RSpec]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Unit Testing]]></category>
		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://www.defusion.org.uk/archives/2008/07/23/testing-that-an-observer-is-registered-in-rails-with-rspec/</guid>
		<description><![CDATA[I've just started using Observers in a Rails application I'm creating and found out that in order to have them picked up by rails you have to manually register the Observers within your environment.rb file, like so:
Display code as plain text
RUBY:




config.active_record.observers = :my_observer 






I like to have as much coverage for any code I write [...]]]></description>
			<content:encoded><![CDATA[<p>I've just started using <a href="http://api.rubyonrails.com/classes/ActiveRecord/Observer.html">Observers</a> in a Rails application I'm creating and found out that in order to have them picked up by rails you have to manually register the Observers within your environment.rb file, like so:</p>
<div class="igBar"><span id="lruby-4"><a href="#" onclick="javascript:showPlainTxt('ruby-4'); return false;">Display code as plain text</a></span></div>
<div class="syntax_hilite"><span class="langName">RUBY:</span>
<div id="ruby-4">
<div class="ruby">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">config.<span style="color:#9900CC;">active_record</span>.<span style="color:#9900CC;">observers</span> = :my_observer </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>I like to have as much coverage for any code I write in Rails, such as associations I've created, validation rules etc. I'm not testing the validation itself (Rails' tests have that covered) what I'm testing is that I've actually applied the validation rule. </p>
<p>So I figured that I should do the same for the Observers which should be registered. I couldn't find any references to anyone else doing this so after a little bit of digging I've come up with the following approach for use with RSpec:<br />
<span id="more-174"></span></p>
<p>matchers/observer_matchers.rb :</p>
<div class="igBar"><span id="lruby-5"><a href="#" onclick="javascript:showPlainTxt('ruby-5'); return false;">Display code as plain text</a></span></div>
<div class="syntax_hilite"><span class="langName">RUBY:</span>
<div id="ruby-5">
<div class="ruby">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#9966CC; font-weight:bold;">module</span> Matchers</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#9966CC; font-weight:bold;">module</span> ObserverMatchers</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; </div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#008000; font-style:italic;">#</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># Used to check that an observer has been registered</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#008000; font-style:italic;">#</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">class</span> BeRegistered</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> initialize<span style="color:#006600; font-weight:bold;">&#40;</span>observer_name<span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; @observer_name = observer_name</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> matches?<span style="color:#006600; font-weight:bold;">&#40;</span>observers<span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; @observers = observers</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; @observers.<span style="color:#9966CC; font-weight:bold;">include</span>?<span style="color:#006600; font-weight:bold;">&#40;</span>@observer_name<span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> failure_message</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#996600;">"expected observer with name of '#{@observer_name}' to be registered but wasn't"</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> negative_failure_message</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#996600;">"expected observer with name of '#{@observer_name}' not to be registered but was"</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#008000; font-style:italic;">#</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># Usage:</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#008000; font-style:italic;">#</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># ActiveRecord::Base.observers.should be_registered(:user_observer)</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> be_registered<span style="color:#006600; font-weight:bold;">&#40;</span>*args<span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; BeRegistered.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span>*args<span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; </div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#9966CC; font-weight:bold;">end</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>models/user_observer_spec.rb</p>
<div class="igBar"><span id="lruby-6"><a href="#" onclick="javascript:showPlainTxt('ruby-6'); return false;">Display code as plain text</a></span></div>
<div class="syntax_hilite"><span class="langName">RUBY:</span>
<div id="ruby-6">
<div class="ruby">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#CC0066; font-weight:bold;">require</span> File.<span style="color:#9900CC;">dirname</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF; font-weight:bold;">__FILE__</span><span style="color:#006600; font-weight:bold;">&#41;</span> + '/../spec_helper'</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">describe UserObserver <span style="color:#9966CC; font-weight:bold;">do</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; it <span style="color:#996600;">"should be registered with the application"</span> <span style="color:#9966CC; font-weight:bold;">do</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; ActiveRecord::Base.<span style="color:#9900CC;">observers</span>.<span style="color:#9900CC;">should</span> be_registered<span style="color:#006600; font-weight:bold;">&#40;</span>:user_observer<span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; ...</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#9966CC; font-weight:bold;">end</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>It really is quite simple, but feel free to use the matcher if you want. Consider it released under BSD licence, no guarantees etc.</p>]]></content:encoded>
			<wfw:commentRss>http://www.defusion.org.uk/archives/2008/07/23/testing-that-an-observer-is-registered-in-rails-with-rspec/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Uploading Files and Images With Flex and Rails</title>
		<link>http://www.defusion.org.uk/archives/2008/04/21/uploading-files-and-images-with-flex-and-rails/</link>
		<comments>http://www.defusion.org.uk/archives/2008/04/21/uploading-files-and-images-with-flex-and-rails/#comments</comments>
		<pubDate>Mon, 21 Apr 2008 21:23:58 +0000</pubDate>
		<dc:creator>Dave</dc:creator>
				<category><![CDATA[Flex]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Productivity]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://www.defusion.org.uk/archives/2008/04/21/uploading-files-and-images-with-flex-and-rails/</guid>
		<description><![CDATA[Having spent most of Saturday trying to get files to upload from a Flex application to a Rails backend, fighting against both Flex and Rails all the way, I thought I'd collect together some of the things that have helped me work through this in the hope that others don't have to spend quite as [...]]]></description>
			<content:encoded><![CDATA[<p>Having spent most of Saturday trying to get files to upload from a Flex application to a Rails backend, fighting against both Flex and Rails all the way, I thought I'd collect together some of the things that have helped me work through this in the hope that others don't have to spend quite as long battling through this. Note however that these are not necessarily best pratices, more a collection of tips that helped me in my situation, there are probably better ways to do some or all of the things that I'll be writing about - and if you know of any improvements/alternatives I'd love to hear about them.<br />
<span id="more-165"></span><br />
In my situation I am uploading images to Rails which is using attachment_fu to handle the images and the thumbnail generation. Some of these tips will be relevant to all more generic issues, such as uploading files from Flex, and some will be more specific, such as making attachment_fu work with images uploaded from Flex.</p>
<p><strong>Uploading files with Flex</strong><br />
To upload files with flex you need to use either the <a href="<br />
http://livedocs.adobe.com/flex/3/langref/flash/net/FileReference.html">FileReference</a> or <a href="http://livedocs.adobe.com/flex/3/langref/flash/net/FileReferenceList.html">FileReferenceList</a> classes, the main difference between these two is that FileReference is for uploading single files and FileReferenceList allows multiple file uploads.</p>
<h2>Issue 1: How to send other data, such as meta/model data with the file upload:</h2>
<p>Say you want to upload an image and save that using Rails along with other model data for that image (such as a title etc.) then you'll have to hack that into the request that FileReference sends. </p>
<p><a href="http://kb.adobe.com/selfservice/viewContent.do?externalId=5534a12f&#038;sliceId=1">This Adobe tech note</a> recommends using the <span class="code">uploadDataFieldName</span> argument of the <span class="code">upload()</span> method, however to me this seems like a really awful hack as you'll then have to parse the name/value pair string in your <span class="code">uploadDataFieldName</span> param at the backend. What you really want is separate parameters (ideally within the POST body).</p>
<p>The only viable solution I could come across was using the query string to pass the parameters through, your mileage may vary on this depending on the parameters you are sending, but I'm pretty sure that no modern browsers enforce the 255 character limit on a <acronym title="Uniform Resource Locator">URL</acronym> anymore.</p>
<h2>Issue 2: Session cookie not sent in Firefox:</h2>
<p>This problem is <a href="http://thanksmister.com/?p=59">explained really well over at Thanks Mister!</a>, it may apply to other browsers (probably the other gecko-based browsers work the same) but quite simply it means that if you're relying on some data in your session during the upload you need to manually pass the session cookie through, however this raises further issues with Rails, so I'll break it down further.</p>
<p><strong>Issue 2: Part 1 -- Passing the cookie when uploading files with FileReference:</strong><br />
It's fairly simple to get around this part of the problem, you just need to include your session identifier within the query string, the biggest issue with this is getting the cookie value -- as Flash doesn't have native access to the browsers cookies.<br />
To get the cookie you'll need to use the <a href="http://livedocs.adobe.com/flex/3/langref/flash/external/ExternalInterface.html">ExternalInterface</a> to call some JavaScript to retrieve the cookie, this is <a href="http://www.restlessthinker.com/blog/?p=39">covered quite nicely in this post</a>. So when working with Rails we just need to retrieve the cookie that lives in whatever we're using as the session ID and pass that through via the query string, but that brings us to another problem:</p>
<p><strong>Issue 2: Part 2 -- Rails won't let you pass session ids in the query string:</strong><br />
So now we need to tweak Rails to let us pass the session id via the query string, luckily there is <a href="http://blog.inquirylabs.com/2006/12/09/getting-the-_session_id-from-swfupload/">another great post on this</a>, however some of the Rails 2 security improvements require further workarounds which are in the comments on that post.</p>
<p>To quickly cover what you need to do is as follows:</p>
<ol>
<li>Add the patch (make sure you get the one for Mongrel/Apache linked at the bottom of the <a href="http://blog.inquirylabs.com/2006/12/09/getting-the-_session_id-from-swfupload/">post</a>) to the <span class="code">CGI::Session</span> class to your application -- it really deserves to live in a plugin rather than the environment.rb file, which you'll have to roll yourself.</li>
<li>For Rails 2 you have to add another override by adding <span class="code">session :cookie_only => false</span> at the controller level. I personally feel it is best to do this in just the controller that you're using to upload the files with.</li>
<li>I still had issues with it not picking up my session -- I was using the Rails 2 default of saving the session information in the cookie. There is probably another hack or change that I could make to get around this, but I chose to move (back to) Active Record sessions but this time using the <a href="http://blog.kovyrin.net/2008/02/06/fastsessions-rails-plugin-released/">Fast Sessions</a> plugin for a bit of a performance boost.
<p>I'll probably look into this again at a later date, but right now I just wanted to get this part working and move on.
</li>
</ol>
<p>So now we've got our file uploading to the backend, within our session and our other model/meta data being sent as well. "Great we're done, what else could go wrong now?" is just the kind of thought you'd be forgiven for having. Of course there was another issue that came up which needed to be handled.</p>
<h2>Issue 3: Attachment_fu and Flex file uploads</h2>
<p>FileReference uploads all files with the MIME type of <span class="code">application/octet-stream</span> which gives us a couple of problems:</p>
<ol>
<li>Your attachment_fu <span class="code">content-type</span> filter will probably reject all uploads out of hand - the easy hack would seem to be to add in the <span class="code">application/octet-stream</span> to your acceptable content-types, but that's an awful hack that basically removes the content-type filtering and doesn't address our second issue.</li>
<li>If using attachment_fu to create thumbnails and you do accept the <span class="code">application/octet-stream</span> MIME then you won't have any thumbnails generated, because as far as attachment_fu is concerned your upload is not an image.</li>
</ol>
<p>Again the solution was only a few searches away, and the changes covered in <a href="http://blog.vixiom.com/2007/12/28/hacking-attachment_fu-to-work-with-flashflex-uploads-and-crop-square-images/">this post over at Vixiom Axioms</a> do fix the issue -- although note that I had issues with that fix and had to apply my own changes - see the comment on that post.</p>
<h2>Conclusion</h2>
<p>So finally we have file uploads working from Flex to Rails, our session information is maintained, we're passing along our model data and our images are being handled as they are supposed to.</p>
<p>This really shouldn't have been this difficult, it should have been a simple case of using FileReference add some data to be POSTed and we'd be done but alas decisions made in/or issues with the Flash player lead to this merry dance of hacks, tweaks and workarounds to make everything sing to the same hymn-sheet.</p>
<p>Hopefully covering this and collecting together these links will save someone else from a wasted day of figuring out the solution to the myriad of problems that I encountered.</p>]]></content:encoded>
			<wfw:commentRss>http://www.defusion.org.uk/archives/2008/04/21/uploading-files-and-images-with-flex-and-rails/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>245 tests, 2094 assertions, 0 failures, 0 errors &#8211; yippie!</title>
		<link>http://www.defusion.org.uk/archives/2008/02/27/245-tests-2094-assertions-0-failures-0-errors-yippie/</link>
		<comments>http://www.defusion.org.uk/archives/2008/02/27/245-tests-2094-assertions-0-failures-0-errors-yippie/#comments</comments>
		<pubDate>Wed, 27 Feb 2008 19:37:39 +0000</pubDate>
		<dc:creator>Dave</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[My Sites]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Unit Testing]]></category>
		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://www.defusion.org.uk/archives/2008/02/27/245-tests-2094-assertions-0-failures-0-errors-yippie/</guid>
		<description><![CDATA[Sorry for the rather pointless post, I've just finished ensuring our test coverage is up to scratch on our project (as I mentioned in the last post). This means that I can get on with the next stage.
Which also means we're one step closer to releasing it.
Which also means I'm one step closer to being [...]]]></description>
			<content:encoded><![CDATA[<p>Sorry for the rather pointless post, I've just finished ensuring our test coverage is up to scratch on our project (as I <a href="/archives/2008/02/20/how-i-increased-my-ruby-on-rails-productivity-on-windows/">mentioned in the last post</a>). This means that I can get on with the next stage.</p>
<p>Which also means we're one step closer to releasing it.</p>
<p>Which also means I'm one step closer to being able to tell you all about it, ohhhhh it's so exciting!</p>]]></content:encoded>
			<wfw:commentRss>http://www.defusion.org.uk/archives/2008/02/27/245-tests-2094-assertions-0-failures-0-errors-yippie/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How I Increased My Ruby on Rails Productivity on Windows</title>
		<link>http://www.defusion.org.uk/archives/2008/02/20/how-i-increased-my-ruby-on-rails-productivity-on-windows/</link>
		<comments>http://www.defusion.org.uk/archives/2008/02/20/how-i-increased-my-ruby-on-rails-productivity-on-windows/#comments</comments>
		<pubDate>Wed, 20 Feb 2008 20:53:15 +0000</pubDate>
		<dc:creator>Dave</dc:creator>
				<category><![CDATA[OOP]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://www.defusion.org.uk/archives/2008/02/20/how-i-increased-my-ruby-on-rails-productivity-on-windows/</guid>
		<description><![CDATA[A couple of weekends ago I was about to begin a large amount of re-factoring of our Ruby on Rails app (more on that to follow) to move it from a functional wireframe of the app to the final polished first version that users can use without cursing us. However I'd knocked together the wireframe [...]]]></description>
			<content:encoded><![CDATA[<p><img id="image109" class="featureImg" src="http://www.defusion.org.uk/wp-content/uploads/2008/02/ubuntu_cola_thumb.jpg" alt="Ubuntu Cola, the way to increase RoR productivity on Windows?" />A couple of weekends ago I was about to begin a large amount of re-factoring of our Ruby on Rails app (more on that to follow) to move it from a functional wireframe of the app to the final polished first version that users can use without cursing us. However I'd knocked together the wireframe version fairly quickly and had not taken time out to put down some decent test coverage, yes I know, and doing the amount of re-factoring I was planning without having any tests to verify that I haven't broken anything isn't a good idea.</p>
<p>So I undertook to get our test coverage up to scratch, I got <a href="http://www.zenspider.com/ZSS/Products/ZenTest/">ZenTest</a> to ensure that the tests get run for every saved modification, which is a great help during development. But this exposed me to something which I had already started to notice but which hadn't become a real issue yet, <em>Ruby on Windows is slower than a 1-legged dog down the dog track</em>. ZenTest was taking 20 seconds or more to even notice a file had changed and then took even longer to begin the test. Combined with Ruby using 100% CPU most of the time this really dented my productivity and I had to do something. Luckily all that spare time I had while I was waiting for the tests to run every time I pressed save meant I could look into resolving the problem.<br />
<span id="more-157"></span><br />
After investigating the problem further it seemed like there was some issue with the startup phase of Ruby, as it took ages to get things like Webrick, mongrel, IRB, Rake tasks etc. started but once they were running everything was fine and dandy.</p>
<p>I came across a few solutions but I opted for <a href="http://blog.rayngwf.com/2008/01/getting-almost-all-ruby-gems-and-c.html">this solution</a> using <a href="http://www.andlinux.org/">andLinux</a> -- which is a install of Ubuntu Linux for running within Windows, think <acronym title="Virtual Machine">VM</acronym> but without the hassle of setting up a <acronym title="Virtual Machine">VM</acronym>, or think Cygwin but more powerful (you can do apt-get to get any Ubuntu package quickly etc.). That tutorial helped me to setup andLinux and my Ruby &amp; Rails environment in under an hour.</p>
<p>Suddenly it was all blazingly fast and <strong>I was happy developing again</strong>.</p>
<p>I then looked to my IDE, I had been using <a href="http://www.aptana.com/">RadRails</a> for <a href="http://www.eclipse.org">eclipse</a> but no longer needed many of it's features I was using and I had noticed that while editing Rails stuff it would start off Ruby (apparently randomly -- well I couldn't figure out the connection between what I was doing and when Ruby would start) which as I say uses 100% of my CPU in Windows. </p>
<p>I wanted something lighter, I wanted something cleaner and I wanted all the cool snippets that <a href="http://macromates.com/">TextMate</a> gives you when developing Ruby/Rails (or pretty much anything) on OS X. Luckily I found exactly what I (and lots of other people) want in <a href="http://www.e-texteditor.com/">TextMate for Windows - in the guise of &quot;e&quot;</a>, which is a fantastic name for launching it via <a href="http://www.launchy.net/">Launchy</a>. </p>
<p>A quick install of <a href="http://www.e-texteditor.com/">e</a> and a play around with the themes to make it easier on the eye and I was in editor heaven (or as close as I've got so far on Windows).</p>
<p>Finally I then found that I had lots of PuTTY windows open to my andLinux install (one for mongrel, one for Zentest, one for log tailing &amp; another for bash), finding which window was which became annoying -- within about 2 minutes. So looking for a tabbed UI for PuTTY I came across two, <a href="http://www.raisin.de/putty-tabs/putty-tabs.html">PuTTY Tabs</a> and <a href="http://puttycm.free.fr/">PuTTY Connection Manager</a>. I tried them both out but it instantly became clear that <a href="http://puttycm.free.fr/">PuTTY Connection Manager</a> was the better of the two for my needs (the fact that it wraps all your PuTTY windows into one with tabs was the main winner). Now I have (at least) four tabs open in PuTTY Connection Manager and rename them all to suit (e.g. [mongrel],[zentest] etc.) making it much, much easier for me to manage.</p>
<p>So the <strong>short-list</strong> of things that increased my Ruby on Rails productivity in Windows is as follows:</p>
<ul>
<li><a href="http://www.andlinux.org/">A Linux install</a> :) to run Ruby on</li>
<li><a href="http://www.zenspider.com/ZSS/Products/ZenTest/">ZenTest</a> autotest, I couldn't live without it anymore</li>
<li><a href="http://www.e-texteditor.com/">e</a></li>
<li><a href="http://puttycm.free.fr/">PuTTY Connection Manager</a></li>
<li><a href="http://www.launchy.net>Launchy</a> which I had before but really does increase productivity.</li>
<li><a hfer="http://www.otakusoftware.com/topdesk/">TopDesk</a> which I've also had for quite a while, but still very useful.</li>
</ul>
<p>I guess the moral of this story is if you want to develop with Ruby on Windows use Linux. I am planning on a move to Ubuntu at some point, but really don't have the time to start from scratch with my system right now.</p>]]></content:encoded>
			<wfw:commentRss>http://www.defusion.org.uk/archives/2008/02/20/how-i-increased-my-ruby-on-rails-productivity-on-windows/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

