<?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"
	>

<channel>
	<title>Flying Machine Studios</title>
	<atom:link href="http://www.flyingmachinestudios.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.flyingmachinestudios.com</link>
	<description></description>
	<pubDate>Wed, 20 May 2009 14:43:44 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.5</generator>
	<language>en</language>
			<item>
		<title>Follow your Followers using Ruby</title>
		<link>http://www.flyingmachinestudios.com/2009/05/20/follow-your-followers-using-ruby/</link>
		<comments>http://www.flyingmachinestudios.com/2009/05/20/follow-your-followers-using-ruby/#comments</comments>
		<pubDate>Wed, 20 May 2009 14:43:44 +0000</pubDate>
		<dc:creator>Daniel Higginbotham</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.flyingmachinestudios.com/?p=44</guid>
		<description><![CDATA[I have the following in a rake task run every 30 minutes. You&#8217;ll need jnunemaker&#8217;s twitter gem.
Follow your followers in Rubyrequire 'twitter'
# Check out the twitter gem docs for using oauth
httpauth = Twitter::HTTPAuth.new&#40;&#34;username&#34;, &#34;password&#34;&#41;
base = Twitter::Base.new&#40;httpauth&#41;
to_follow_ids = base.follower_ids - base.friend_ids
unavailable_count = 0
to_follow_ids.each do &#124;tfid&#124;
&#160; begin
&#160; &#160; base.friendship_create&#40;tfid, true&#41;
&#160; rescue Twitter::General
&#160; &#160; # Twitter::General is raised [...]]]></description>
			<content:encoded><![CDATA[<p>I have the following in a rake task run every 30 minutes. You&#8217;ll need jnunemaker&#8217;s twitter gem.</p>
<p></p><p><strong><a href='http://snipplr.com/view/15194/follow-your-followers-in-ruby'>Follow your followers in Ruby</a></strong><br/></p><div class='code' style='border: 1px dotted; overflow: auto; white-space:nowrap;'><ol><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#CC0066; font-weight:bold;">require</span> 'twitter'</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#008000; font-style:italic;"># Check out the twitter gem docs for using oauth</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">httpauth = Twitter::HTTPAuth.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;username&quot;</span>, <span style="color:#996600;">&quot;password&quot;</span><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;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">base = Twitter::Base.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span>httpauth<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;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">to_follow_ids = base.<span style="color:#9900CC;">follower_ids</span> - base.<span style="color:#9900CC;">friend_ids</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">unavailable_count = <span style="color:#006666;">0</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">to_follow_ids.<span style="color:#9900CC;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> |tfid|</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#9966CC; font-weight:bold;">begin</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; base.<span style="color:#9900CC;">friendship_create</span><span style="color:#006600; font-weight:bold;">&#40;</span>tfid, <span style="color:#0000FF; font-weight:bold;">true</span><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;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#9966CC; font-weight:bold;">rescue</span> Twitter::General</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># Twitter::General is raised for 403 errors</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># Which occur when you're trying to follow someone who's been banned by twitter</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; base.<span style="color:#9900CC;">block</span><span style="color:#006600; font-weight:bold;">&#40;</span>tfid<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;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#9966CC; font-weight:bold;">rescue</span> Twitter::Unavailable </div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># Wait and try again if twitter's telling you to wait</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#CC0066; font-weight:bold;">sleep</span> <span style="color:#006666;">5</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">if</span> unavailable_count &lt; <span style="color:#006666;">3</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">retry</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; unavailable_count += <span style="color:#006666;">1</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><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-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><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-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#9966CC; font-weight:bold;">end</span> </div></li></ol></div><p></p>
]]></content:encoded>
			<wfw:commentRss>http://www.flyingmachinestudios.com/2009/05/20/follow-your-followers-using-ruby/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Aikidoka Prevents Ruby Namespace Collisions</title>
		<link>http://www.flyingmachinestudios.com/2009/05/10/aikidoka-prevents-ruby-namespace-collisions/</link>
		<comments>http://www.flyingmachinestudios.com/2009/05/10/aikidoka-prevents-ruby-namespace-collisions/#comments</comments>
		<pubDate>Sun, 10 May 2009 14:37:16 +0000</pubDate>
		<dc:creator>Daniel Higginbotham</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.flyingmachinestudios.com/?p=43</guid>
		<description><![CDATA[Recently I fell victim to the Twitter-Mash / Extlib-DataMapper-Mash namespace collision. To get around this problem, I&#8217;ve created a new gem, Aikidoka.
Here&#8217;s what happened when I tried to use Twitter when Extlib had already been loaded:

irb(main):001:0> require 'Twitter'
=> ["Twitter"]
irb(main):002:0> Twitter::Search.new("bokken").fetch
SystemStackError: stack level too deep

Here&#8217;s what happens when you use Aikidoka:

irb(main):001:0> require 'aikidoka'
=> ["Aikidoka"]
irb(main):002:0> Aikidoka.rename("Mash" => [...]]]></description>
			<content:encoded><![CDATA[<p>Recently I fell victim to the Twitter-Mash / Extlib-DataMapper-Mash <a href="http://blog.zerosum.org/2009/4/17/why-namespaces-are-important">namespace collision</a>. To get around this problem, I&#8217;ve created a new gem, <a href="http://github.com/flyingmachine/aikidoka/tree/master">Aikidoka</a>.</p>
<p>Here&#8217;s what happened when I tried to use Twitter when Extlib had already been loaded:</p>
<p><code>
<pre>irb(main):001:0> require 'Twitter'
=> ["Twitter"]
irb(main):002:0> Twitter::Search.new("bokken").fetch
SystemStackError: stack level too deep</pre>
<p></code></p>
<p>Here&#8217;s what happens when you use Aikidoka:</p>
<p><code>
<pre>irb(main):001:0> require 'aikidoka'
=> ["Aikidoka"]
irb(main):002:0> Aikidoka.rename("Mash" => "Twitter::Mash"){require 'twitter'}
=> ["Mash"]
irb(main):003:0> Twitter::Search.new("aikidoka").fetch
=> &lt;Mash completed_in=0.052875 max_id=1754360060 next_page="?page=2&#038;max_id=1754360060&#038;q=aikidoka"
etc...
</pre>
<p></code></p>
<p>It works! What this does is namespace the Mash defined when I require the Twitter gem, so that Mash is now Twitter::Mash. Also, Extlib&#8217;s Mash is still there, untouched, so you don&#8217;t need to worry about that. Here&#8217;s how Aikidoka does its magic:</p>
<ol>
<li>It temporarily renames existing constants so that they don&#8217;t get clobbered. In this case, &#8220;Mash&#8221; is renamed to &#8220;AikidokaMash&#8221;. Right now this only works with top-level constants.</li>
<li>It yields to the given block. This block should define the constants you want permanently renamed/namespaced. In this case, we&#8217;re requiring &#8220;twitter&#8221;, which in turn requires &#8220;mash&#8221;. &#8220;mash&#8221; defines the constant we want to rename, Mash.</li>
<li>It creates modules as necessary to create the namespace. In this case, the module Twitter is already defined so that&#8217;s used. However, if we wanted to rename &#8220;Mash&#8221; to &#8220;Potatoes::Mash&#8221;, then a module named &#8220;Potatoes&#8221; would have been created.</li>
<li>It assigns the object referred to by the old constant to its new constant. &#8220;Twitter::Mash&#8221; now refers to the same object that &#8220;Mash&#8221; refers to.</li>
<li>Old constants are removed to clean up the namespace. The constant &#8220;Mash&#8221; no longer exists, the object it used to refer to lives on.</li>
<li>The constants temporarily renamed in step 1 are now given their original names back. Extlib&#8217;s &#8220;Mash&#8221; is no longer &#8220;AikidokaMash&#8221;; it&#8217;s &#8220;Mash&#8221; again.</li>
</ol>
<p>The code is very simple - a total of 67 lines in one file with decent specs - so hopefully it&#8217;s easy to dig into.</p>
<p>Right now Aikidoka is best at nesting an existing top-level constant within another constant of a different name. I haven&#8217;t tried doing something like <code>Aikidoka.rename("Mash" => "Mash::Twitter")</code> or <code>Aikidoka.rename("ActiveRecord::Base" => "ARBase")</code>, and those examples probably wouldn&#8217;t work.</p>
<p>All in all, it does what I want it to and seems to work OK :) You can install it with &#8220;<strong><code>gem install flyingmachine-aikidoka</code></strong>&#8220;. If you&#8217;re wondering about the name, aikido is a martial art designed to resolve conflict harmoniously, and an aikidoka is a student of aikido.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.flyingmachinestudios.com/2009/05/10/aikidoka-prevents-ruby-namespace-collisions/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Twitter and Datamapper fix</title>
		<link>http://www.flyingmachinestudios.com/2009/05/07/twitter-and-datamapper-fix/</link>
		<comments>http://www.flyingmachinestudios.com/2009/05/07/twitter-and-datamapper-fix/#comments</comments>
		<pubDate>Thu, 07 May 2009 19:18:44 +0000</pubDate>
		<dc:creator>Daniel Higginbotham</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.flyingmachinestudios.com/?p=42</guid>
		<description><![CDATA[I&#8217;ve forked jnunemaker&#8217;s twitter and updated to use peterpunk&#8217;s Mhash gem instead of the Mash gem it was using. This avoids the namespace collision with Mash in datamapper&#8217;s extlib library.
http://github.com/flyingmachine/twitter/tree/master
git://github.com/flyingmachine/twitter.git
]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve forked jnunemaker&#8217;s twitter and updated to use peterpunk&#8217;s Mhash gem instead of the Mash gem it was using. This avoids the namespace collision with Mash in datamapper&#8217;s extlib library.</p>
<p>http://github.com/flyingmachine/twitter/tree/master<br />
git://github.com/flyingmachine/twitter.git</p>
]]></content:encoded>
			<wfw:commentRss>http://www.flyingmachinestudios.com/2009/05/07/twitter-and-datamapper-fix/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Patch for Fiveruns Tuneup on Merb 1.0.11</title>
		<link>http://www.flyingmachinestudios.com/2009/04/23/patch-for-fiveruns-tuneup-on-merb-1011/</link>
		<comments>http://www.flyingmachinestudios.com/2009/04/23/patch-for-fiveruns-tuneup-on-merb-1011/#comments</comments>
		<pubDate>Thu, 23 Apr 2009 22:04:14 +0000</pubDate>
		<dc:creator>Daniel Higginbotham</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.flyingmachinestudios.com/?p=41</guid>
		<description><![CDATA[FiveRuns Tuneup for Merb didn&#8217;t work out of the box for me. The following patch to the gem got it working:
Patch for Fiveruns Tuneup on Merb 1.0.11diff -r fiveruns_tuneup_merb-0.5.3/lib/fiveruns_tuneup_merb/instrumentation.rb fiveruns_tuneup_merb-0.5.3.updated/lib/fiveruns_tuneup_merb/instrumentation.rb
170c170
&#60;&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; FiverunsTuneupMerb::Instrumentation.format_sql&#40;query, adapter.send&#40;:update_statement, query&#41;, attributes&#41;,
---
&#62;&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; FiverunsTuneupMerb::Instrumentation.format_sql&#40;query, adapter.send&#40;:update_statement, attributes.keys, query&#41;, attributes&#41;,
diff [...]]]></description>
			<content:encoded><![CDATA[<p>FiveRuns Tuneup for Merb didn&#8217;t work out of the box for me. The following patch to the gem got it working:</p>
<p></p><p><strong><a href='http://snipplr.com/view/14346/patch-for-fiveruns-tuneup-on-merb-1011'>Patch for Fiveruns Tuneup on Merb 1.0.11</a></strong><br/></p><div class='code' style='border: 1px dotted; overflow: auto; white-space:nowrap;'><ol><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">diff -r fiveruns_tuneup_merb<span style="">-0.5</span><span style="">.3</span>/lib/fiveruns_tuneup_merb/instrumentation.rb fiveruns_tuneup_merb<span style="">-0.5</span><span style="">.3</span>.updated/lib/fiveruns_tuneup_merb/instrumentation.rb</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #440088;">170c170</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #991111;">&lt;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; FiverunsTuneupMerb::Instrumentation.format_sql<span style="">&#40;</span>query, adapter.send<span style="">&#40;</span>:update_statement, query<span style="">&#41;</span>, attributes<span style="">&#41;</span>,</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #888822;">---</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #00b000;">&gt;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; FiverunsTuneupMerb::Instrumentation.format_sql<span style="">&#40;</span>query, adapter.send<span style="">&#40;</span>:update_statement, attributes.keys, query<span style="">&#41;</span>, attributes<span style="">&#41;</span>,</span></span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">diff -r fiveruns_tuneup_merb<span style="">-0.5</span><span style="">.3</span>/lib/fiveruns_tuneup_merb.rb fiveruns_tuneup_merb<span style="">-0.5</span><span style="">.3</span>.updated/lib/fiveruns_tuneup_merb.rb</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #440088;"><span style="">5</span>,6c5,<span style="">6</span></span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #991111;">&lt;&nbsp; &nbsp;load_dependency 'merb-slices'</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #991111;">&lt;&nbsp; &nbsp;load_dependency 'fiveruns_tuneup_core'</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #888822;">---</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #00b000;">&gt;&nbsp; &nbsp;load_dependency 'merb-slices', nil</span></span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #00b000;">&gt;&nbsp; &nbsp;load_dependency 'fiveruns_tuneup_core', nil </span></div></li></ol></div><p></p>
]]></content:encoded>
			<wfw:commentRss>http://www.flyingmachinestudios.com/2009/04/23/patch-for-fiveruns-tuneup-on-merb-1011/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Form Element Objects in Merb</title>
		<link>http://www.flyingmachinestudios.com/2009/04/08/view-objects-in-merb/</link>
		<comments>http://www.flyingmachinestudios.com/2009/04/08/view-objects-in-merb/#comments</comments>
		<pubDate>Wed, 08 Apr 2009 11:08:57 +0000</pubDate>
		<dc:creator>Daniel Higginbotham</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.flyingmachinestudios.com/?p=32</guid>
		<description><![CDATA[Overview
I&#8217;ve been trying to make merb a little bit easier to use by implementing form element classes. The approach I&#8217;ve taken is influenced by my experience with Cocoa. The view classes I&#8217;ve created encapsulate behavior for displaying complex form elements and for parsing the data sent to controllers by the form elements.
One great advantage that [...]]]></description>
			<content:encoded><![CDATA[<h2>Overview</h2>
<p>I&#8217;ve been trying to make merb a little bit easier to use by implementing form element classes. The approach I&#8217;ve taken is influenced by my experience with Cocoa. The view classes I&#8217;ve created encapsulate behavior for displaying complex form elements and for parsing the data sent to controllers by the form elements.</p>
<p>One great advantage that Cocoa development has over web development with an MVC framework like merb is that your views are first-class objects and can be communicated with directly using the same language as the rest of the system. With a web app, you have to go to extra lengths so that your Model or Controller will correctly get data from a form element if the element is even slightly complex. Most likely you&#8217;ll need to use Javascript in addition to whatever backend language you&#8217;re using. You&#8217;ll probably also have a lot of code to parse those elements in your controllers, spreading the concept your form element represents all over the place. In Cocoa, interacting with complex &#8220;form elements&#8221; is easier and cleaner.</p>
<h2>Brief Cocoa Example</h2>
<p>One iPhone app I&#8217;m on working on stores a time interval in seconds. Since it&#8217;s not very user-friendly to make a user figure that out, I use a picker that allows him to specify days, hours, and minutes.</p>
<p><a href="http://www.flyingmachinestudios.com/wp-content/uploads/2009/04/picker-example.png"><img class="alignnone size-full wp-image-36" title="Interval Picker" src="http://www.flyingmachinestudios.com/wp-content/uploads/2009/04/picker-example.png" alt="Picker for days, hours, and minutes" width="320" height="249" /></a></p>
<p>This picker is an instance of a subclass of UIPickerView, which means it&#8217;s a first-class object and I can define methods on it to get at its tasty insides. The advantage here is that methods that belong together conceptually are placed together physically. The salient method is below:</p>
<p></p><p><strong><a href='http://snipplr.com/view/13863/picker-valueinseconds'>picker valueInSeconds</a></strong><br/></p><div class='code' style='border: 1px dotted; overflow: auto; white-space:nowrap;'><ol><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">- (NSInteger)valueInSeconds</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">{</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; NSInteger dayRow = [self selectedRowInComponent:0];</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; NSInteger hourRow = [self selectedRowInComponent:1];</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; NSInteger minuteRow = [self selectedRowInComponent:2];</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; NSInteger daySeconds = dayRow * 24 * 60 * 60;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; NSInteger hourSeconds = hourRow * 60 * 60;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; NSInteger minuteSeconds = minuteRow * 5 * 60;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; </div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; return (daySeconds + hourSeconds + minuteSeconds);</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">}</div></li></ol></div><p></p>
<p>Therefore when I&#8217;m ready to set the time interval, I just do the following:</p>
<p>medication.interval = [intervalPicker valueInSeconds];</p>
<p>From what I understand, this is all nothing special in Cocoa development.</p>
<h2>The Web App Problem</h2>
<p>merb (and Rails) have no mechanism for treating form elements as objects. Form elements are displayed using javascript, templates, and helpers. Then their data is sent to a controller as a hash. They&#8217;re usually parsed with code in the controller.</p>
<p>For example, <a href="http://www.traineo.com">traineo.com</a> we have the following form elements:</p>
<p><a href="http://www.flyingmachinestudios.com/wp-content/uploads/2009/04/american-orig.png"><img class="alignnone size-full wp-image-37" title="American units" src="http://www.flyingmachinestudios.com/wp-content/uploads/2009/04/american-orig.png" alt="American units, weight in lbs" width="444" height="110" /></a></p>
<p><a href="http://www.flyingmachinestudios.com/wp-content/uploads/2009/04/british-orig.png"><img class="alignnone size-full wp-image-38" title="British units" src="http://www.flyingmachinestudios.com/wp-content/uploads/2009/04/british-orig.png" alt="British units, weight in stone" width="500" height="109" /></a></p>
<p>For these form elements, we use javascript to change the weight input when the user clicks a radio button.</p>
<p>Initially, we had some code in our controller to get the &#8220;weight&#8221; value and convert it to kilograms so that we could then pass it to a model. Something like</p>
<p><code>
<pre>if (params[:weight_input]["stone"])
# Convert from stone to kg
elsif (params[:weight_input]["american"])
# Convert from lbs to kg
else
# Leave as is; already in kg</pre>
<p></code></p>
<p>This worked ok, but once we started placing the weight input fields in other forms, the code had to be improved. We could have created a method in ApplicationController for parsing date input, but it didn&#8217;t seem like good OO programming to make ApplicationController aware of and responsible for one set of form fields. Better to make a class and take advantage of Ruby&#8217;s object goodness.</p>
<p>Enough of my blathering - here&#8217;s the code:</p>
<p></p><p><strong><a href='http://snipplr.com/view/13864/merb-widget'>merb widget</a></strong><br/></p><div class='code' style='border: 1px dotted; overflow: auto; white-space:nowrap;'><ol><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#008000; font-style:italic;"># lib/widgets/widget.rb</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#008000; font-style:italic;"># Superclass for our form element &quot;widgets&quot;</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#9966CC; font-weight:bold;">class</span> Widget</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#9966CC; font-weight:bold;">include</span> Merb::GlobalHelpers</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><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;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#008000; font-style:italic;"># This is necessary to include Merb::GlobalHelpers</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; class_inheritable_accessor :_default_builder</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><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;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#008000; font-style:italic;"># These are for convenience</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; attr_accessor :params</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; attr_accessor :session</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><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;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> initialize<span style="color:#006600; font-weight:bold;">&#40;</span>params = <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">&#125;</span>, session = <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">&#125;</span><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;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">params</span> = params</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">session</span> = session</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><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-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><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;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> value</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><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-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><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;"><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;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#008000; font-style:italic;"># lib/widgets/weight_input_switcher.rb</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#9966CC; font-weight:bold;">class</span> WeightInputSwitcher &lt; Widget</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; attr_accessor :attribute_name, :weight_in_kg, :unit_preference</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><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;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#008000; font-style:italic;"># View methods</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> setup<span style="color:#006600; font-weight:bold;">&#40;</span>attribute_name, weight_in_kg = <span style="color:#0000FF; font-weight:bold;">nil</span>, unit_preference = session<span style="color:#006600; font-weight:bold;">&#91;</span>:unit_preference<span style="color:#006600; font-weight:bold;">&#93;</span><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;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">attribute_name</span> = attribute_name</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">weight_in_kg</span> = weight_in_kg</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">unit_preference</span> = unit_preference</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#0000FF; font-weight:bold;">self</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><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-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><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;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> switcher</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; html = <span style="color:#996600;">&quot;&lt;div class='weight_input_switcher'&gt;&quot;</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; html += weight_input<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;lbs&quot;</span><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;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; html += weight_input<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;kg&quot;</span><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;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; html += weight_input<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;st&quot;</span><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;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; html += <span style="color:#996600;">&quot;&lt;/div&gt;&quot;</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; html</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><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-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><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;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> weight_input</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; html = <span style="color:#996600;">&quot;&lt;span class='weight_input #{unit_preference}'&gt;&quot;</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; html += weight_input_field</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; html += <span style="color:#996600;">&quot;&lt;/span&gt;&quot;</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><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-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><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;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> weight_input_field</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">if</span> unit_preference == <span style="color:#996600;">&quot;st&quot;</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; stone, lbs = <span style="color:#9966CC; font-weight:bold;">if</span> weight_in_kg.<span style="color:#9900CC;">to_i</span> == <span style="color:#006666;">0</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">&quot;&quot;</span>,<span style="color:#996600;">&quot;&quot;</span><span style="color:#006600; font-weight:bold;">&#93;</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">else</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; weight_input_value<span style="color:#006600; font-weight:bold;">&#40;</span>weight_in_kg, unit_preference<span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#CC0066; font-weight:bold;">split</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot; st &quot;</span><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;"><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;"><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;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; html = text_field attribute_name, :value =&gt; stone, :name =&gt; <span style="color:#996600;">&quot;weight_input[stone]&quot;</span>, :<span style="color:#9966CC; font-weight:bold;">class</span> =&gt; <span style="color:#996600;">&quot;weight_input_field stone&quot;</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; html += <span style="color:#996600;">&quot;&lt;span class='weight_unit'&gt;stone&lt;/span&gt;&quot;</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; html += text_field attribute_name, :value =&gt; lbs, :name =&gt; <span style="color:#996600;">&quot;weight_input[lbs]&quot;</span>, :<span style="color:#9966CC; font-weight:bold;">class</span> =&gt; <span style="color:#996600;">&quot;weight_input_field stone lbs&quot;</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; html += <span style="color:#996600;">&quot;&lt;span class='weight_unit'&gt;lbs&lt;/span&gt;&quot;</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">else</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; value = weight_input_value<span style="color:#006600; font-weight:bold;">&#40;</span>weight_in_kg, unit_preference<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;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; </div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; html = text_field attribute_name, :value =&gt; value, :name =&gt; <span style="color:#996600;">&quot;weight_input&quot;</span>, :<span style="color:#9966CC; font-weight:bold;">class</span> =&gt; <span style="color:#996600;">&quot;weight_input_field&quot;</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; html += <span style="color:#996600;">&quot;&lt;span class='weight_unit'&gt;&quot;</span> + unit_preference.<span style="color:#9900CC;">to_s</span> + <span style="color:#996600;">&quot;&lt;/span&gt;&quot;</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><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-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; html</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><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-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><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;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#008000; font-style:italic;"># Parse methods</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#008000; font-style:italic;"># We kinda cheat here and use params. Need to figure out a better way to do this.</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> value</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">if</span> params<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">&quot;weight_input&quot;</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">&quot;stone&quot;</span><span style="color:#006600; font-weight:bold;">&#93;</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; <span style="color:#996600;">&quot;#{params[&quot;</span>weight_input<span style="color:#996600;">&quot;][&quot;</span>stone<span style="color:#996600;">&quot;]} st #{params[&quot;</span>weight_input<span style="color:#996600;">&quot;][&quot;</span>lbs<span style="color:#996600;">&quot;]} lbs&quot;</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">else</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; <span style="color:#996600;">&quot;#{params[&quot;</span>weight_input<span style="color:#996600;">&quot;]} #{Units.weight_full_to_abbreviation_map[unit_preference]}&quot;</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><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-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><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-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><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;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; private</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> weight_input_value<span style="color:#006600; font-weight:bold;">&#40;</span>weight_in_kg, unit_preference<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;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">begin</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; weight_in_kg.<span style="color:#9900CC;">to_display_weight_without_unit</span><span style="color:#006600; font-weight:bold;">&#40;</span>unit_preference<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;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">rescue</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; <span style="color:#996600;">&quot;&quot;</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><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-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><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-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><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;"><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;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#008000; font-style:italic;"># The following is added to global_helpers.rb</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#9966CC; font-weight:bold;">def</span> widget<span style="color:#006600; font-weight:bold;">&#40;</span>klass, *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;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; klass.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span>params, session<span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">setup</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;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><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;"><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;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#008000; font-style:italic;"># An example of using the &quot;Widget&quot; to display form elements</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">widget<span style="color:#006600; font-weight:bold;">&#40;</span>WeightInputSwitcher, :weight, @current_user.<span style="color:#9900CC;">current_weight</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">switcher</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><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;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#008000; font-style:italic;"># An example of using the &quot;Widget&quot; to get the value of form elements</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">weight_widget = widget<span style="color:#006600; font-weight:bold;">&#40;</span>WeightInputSwitcher, :weight, <span style="color:#006666;">0</span>, <span style="color:#996600;">&quot;&quot;</span>, user<span style="color:#006600; font-weight:bold;">&#91;</span>:unit_preference<span style="color:#006600; font-weight:bold;">&#93;</span><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;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">weight = weight_widget.<span style="color:#9900CC;">value</span> </div></li></ol></div><p></p>
<p>So my code could use some improvement, but I think it lays some good groundwork for treating form elements as objects in Merb. Any feedback would be greatly appreciated!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.flyingmachinestudios.com/2009/04/08/view-objects-in-merb/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Some Things I Learned in 2008 (That Hopefully I won&#8217;t Have to Re-Learn in 2009)</title>
		<link>http://www.flyingmachinestudios.com/2008/12/31/some-things-i-learned-in-2008-that-hopefully-i-wont-have-to-re-learn-in-2009/</link>
		<comments>http://www.flyingmachinestudios.com/2008/12/31/some-things-i-learned-in-2008-that-hopefully-i-wont-have-to-re-learn-in-2009/#comments</comments>
		<pubDate>Thu, 01 Jan 2009 03:48:19 +0000</pubDate>
		<dc:creator>Daniel Higginbotham</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.flyingmachinestudios.com/?p=31</guid>
		<description><![CDATA[Don&#8217;t wait until you &#8220;feel like it&#8221; to do something
In fact, doing the thing usually puts you in the right mood to be doing it.I learned this one when my uncle moved from Boston to New Jersey. Before, he was a 45 minute drive away. Now, I&#8217;d have to travel at least 4 hours to [...]]]></description>
			<content:encoded><![CDATA[<h2>Don&#8217;t wait until you &#8220;feel like it&#8221; to do something</h2>
<p>In fact, doing the thing usually puts you in the right mood to be doing it.I learned this one when my uncle moved from Boston to New Jersey. Before, he was a 45 minute drive away. Now, I&#8217;d have to travel at least 4 hours to see him. I regret that I hadn&#8217;t gone to see him more, even though I didn&#8217;t always feel like it.</p>
<h2>Everything will take longer than you expect it to</h2>
<p>Well, almost everything. Phone calls that should take 5 minutes will take 20. Errands that you think will take one hour will take two. Even when you think you&#8217;ve learned and adjusted your expectations, things will still take longer. This one hit me when my friend, my girlfriend, and I drove to downtown Boston to see a friend perform. We should have been 10 minutes early, but we couldn&#8217;t find a parking spot and arrived a little late. This lesson was confirmed recently when I left 30 minutes early to go to an aikido class and ended up 5 minutes late because of unexpected traffic.</p>
<h2>There&#8217;s no reason to worry</h2>
<p>Are you worried that something bad is going to happen? Well something bad IS going to happen, so how&#8217;s worrying going to make any difference? Besides, worrying will drain your resources prematurely and make it harder for you to cope. I learned this one from <a href="http://www.flyingmachinestudios.com/2008/11/29/what-ive-learned-from-getting-laid-off-twice-in-three-months/">getting laid off twice in three months</a>.</p>
<h2>What it means</h2>
<p>Around the time that I got laid off for the second time, I was listening to the <a href="http://www.alanwattspodcast.com/">Alan Watts podcast</a> a lot. He talks mostly about buddhism and mentioned that &#8220;nirvana&#8221; means &#8220;breathe out&#8221; - as in, if you hold your breath, you&#8217;ll suffocate. In the same way, if you cling to life, you&#8217;ll &#8220;suffocate&#8221;. But if you breathe out, your breath will come back to you, and it works the same with life.</p>
<p>I try to keep this in mind when I have too much inertia to do something, when I&#8217;m becoming impatient because something&#8217;s taking longer than I expected, or when I find my energy being drained by worry.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.flyingmachinestudios.com/2008/12/31/some-things-i-learned-in-2008-that-hopefully-i-wont-have-to-re-learn-in-2009/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Upgrading from Merb 1.0 to 1.0.3</title>
		<link>http://www.flyingmachinestudios.com/2008/12/02/upgrading-from-merb-10-to-103/</link>
		<comments>http://www.flyingmachinestudios.com/2008/12/02/upgrading-from-merb-10-to-103/#comments</comments>
		<pubDate>Tue, 02 Dec 2008 17:40:48 +0000</pubDate>
		<dc:creator>Daniel Higginbotham</dc:creator>
		
		<category><![CDATA[Merb]]></category>

		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.flyingmachinestudios.com/?p=30</guid>
		<description><![CDATA[I ran into a couple snags when upgrading, but doing the following solved my problems:

updating the do_mysql gem
updating the do_sqlite3 gem
installing dm-core from source (solves the problem described here)

git clone git://github.com/sam/dm-core.git
cd dm-core
rake package
sudo gem install pkg/dm-core-0.9.7



]]></description>
			<content:encoded><![CDATA[<p>I ran into a couple snags when upgrading, but doing the following solved my problems:</p>
<ul>
<li>updating the do_mysql gem</li>
<li>updating the do_sqlite3 gem</li>
<li>installing dm-core from source (solves the problem described <a href="http://onruby.flempo.com/2008/11/18/merb-cant-connect-to-the-database-with-data_objects_adapterrb137in-initialize-wrong-number-of-arguments-8-for-1-argumenterror/">here</a>)
<ul>
<li>git clone git://github.com/sam/dm-core.git</li>
<li>cd dm-core</li>
<li>rake package</li>
<li>sudo gem install pkg/dm-core-0.9.7</li>
</ul>
</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.flyingmachinestudios.com/2008/12/02/upgrading-from-merb-10-to-103/feed/</wfw:commentRss>
		</item>
		<item>
		<title>What I&#8217;ve Learned from Getting Laid Off Twice in Three Months</title>
		<link>http://www.flyingmachinestudios.com/2008/11/29/what-ive-learned-from-getting-laid-off-twice-in-three-months/</link>
		<comments>http://www.flyingmachinestudios.com/2008/11/29/what-ive-learned-from-getting-laid-off-twice-in-three-months/#comments</comments>
		<pubDate>Sat, 29 Nov 2008 19:48:35 +0000</pubDate>
		<dc:creator>Daniel Higginbotham</dc:creator>
		
		<category><![CDATA[Projects]]></category>

		<guid isPermaLink="false">http://www.flyingmachinestudios.com/?p=29</guid>
		<description><![CDATA[I wrote the following for Happy Job Search.
In August I got laid off because the startup I was working for was running out of funds. After getting a new job, I got laid off again in October, for the same reason. The first time was distressing to the point where I began to feel general [...]]]></description>
			<content:encoded><![CDATA[<p>I wrote the following for <a href="http://www.happyjobsearch.com">Happy Job Search</a>.</p>
<p>In August I got laid off because the startup I was working for was running out of funds. After getting a new job, I got laid off again in October, for the same reason. The first time was distressing to the point where I began to feel general anxiety - I would be sitting doing nothing and I would still feel a lot of anxiety. The second time around I handled the fallout and the job search much better, to the point where it was even fun. Here are some practices that worked well:</p>
<h2>1. Unwind.</h2>
<p>The first time I got laid off I immediately started to freak and start to look for new jobs. Half of the emails I sent didn&#8217;t have a resume attached. My cover letter was sloppy.</p>
<p>The second time I went out and got some dinner with my girlfriend and watched a movie. I was able to approach my situation much more objectively afterwords.</p>
<p>If you immediately get frantic or distraught, it&#8217;s hard to get yourself out of that place. Getting yourself in the right frame of the mind at the beginning will allow you to approach your job search with calmness.</p>
<h2>2. Ask for help.</h2>
<p>The first time I got laid off I tried to deal with everything myself. The result that was I felt like no one cared (surprise!). Having to struggle with that on top of everything else made me miserable.</p>
<p>The second time I immediately talked to my girlfriend about it, and talked to a couple friends soon after. I asked my friends to see if they knew anyone who needed a web developer. I didn&#8217;t get any referrals from them, but it was nice to feel cared for.</p>
<p>Looking back, the reason I tried to handle it myself the first time was because I felt ashamed. I pride myself on my work (and my ability to take care of my girlfriend, who is chronically ill), so getting laid off was a blow to my ego in a way. There&#8217;s no reason to feel this way, though.</p>
<h2>3. Exercise.</h2>
<p>I actually got this right the first time. Exercise helps freaking everything. It helped reduce my anxiety and it gave me more energy. It also gave me a feeling of accomplishment.</p>
<p>A <a href="http://www.amazon.com/gp/product/0316113506?ie=UTF8&amp;tag=aflyingmachin-20&amp;linkCode=as2&amp;camp=1789&amp;creative=390957&amp;creativeASIN=0316113506">great book</a><img style="border: medium none  ! important; margin: 0px ! important;" src="http://www.assoc-amazon.com/e/ir?t=aflyingmachin-20&amp;l=as2&amp;o=1&amp;a=0316113506" border="0" alt="" width="1" height="1" /> has recently been written on the incredible benefits of exercise, and if you don&#8217;t already have a regimen I recommend you read it.</p>
<h2>4. Get organized</h2>
<p>Getting organized allowed me to feel in control. The first time, I was pretty haphazard in my approach to searching for jobs and following up. The result was that I felt constant anxiety because I wasn&#8217;t sure what I needed to next. I also didn&#8217;t have any clear way to see what I was accomplishing in my job search, so I never felt OK with the effort I was putting forth.</p>
<p>I created this web site to help me get organized, and using it helped reduce my anxiety. In addition to this site, here are a couple lists I used to get organized:</p>
<ul>
<li><a href="http://www.happyjobsearch.com/general/job_checklist">Job checklist</a> - what do with each application</li>
<li>&#8220;<a href="http://www.happyjobsearch.com/general/things_i_can_do_list">Things I can do</a>&#8221; - a list I made of possible projects to enhance my marketability and possibly provide revenue. I picked one major one (working on this site) and focused on it.</li>
</ul>
<h2>5. Always have something to move forward on.</h2>
<p>The real benefit of getting organized was that I always had something to move forward on. This helped keep me from dwelling on rejections and it kept me motivated and excited. This was a huge improvement from the first layoff, where I was basically a mess :)</p>
<p>All of these practices helped me cope better.  If you have any techniques that worked for you, please <a>email</a> them to me!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.flyingmachinestudios.com/2008/11/29/what-ive-learned-from-getting-laid-off-twice-in-three-months/feed/</wfw:commentRss>
		</item>
		<item>
		<title>DRY up controllers with params_to_objects</title>
		<link>http://www.flyingmachinestudios.com/2008/09/06/dry-up-controllers-with-params_to_objects/</link>
		<comments>http://www.flyingmachinestudios.com/2008/09/06/dry-up-controllers-with-params_to_objects/#comments</comments>
		<pubDate>Sun, 07 Sep 2008 00:44:07 +0000</pubDate>
		<dc:creator>Daniel Higginbotham</dc:creator>
		
		<category><![CDATA[Programming]]></category>

		<category><![CDATA[Rails]]></category>

		<guid isPermaLink="false">http://www.flyingmachinestudios.com/?p=28</guid>
		<description><![CDATA[The following allows you to get rid of the numerous &#8220;Model.find(params[:id])&#8221; calls in your controllers. I&#8217;m pretty sure I&#8217;ve seen similar solutions out there, so if anyone wants to link to those in the comments that&#8217;d be helpful.

# Example
class BooksController < ApplicationController
  params_to_objects :library, :book 

  def show
    # if [...]]]></description>
			<content:encoded><![CDATA[<p>The following allows you to get rid of the numerous &#8220;Model.find(params[:id])&#8221; calls in your controllers. I&#8217;m pretty sure I&#8217;ve seen similar solutions out there, so if anyone wants to link to those in the comments that&#8217;d be helpful.<br />
<span id="more-28"></span></p>
<pre><code># Example
class BooksController < ApplicationController
  params_to_objects :library, :book 

  def show
    # if this method corresponds to /libraries/{id}/books/{id}
    # then @book and @library are automatically created
  end
end

# Put the following in ApplicationController
class << self
  # you can use the *_filter options of :only, etc
  # also, if you have namespaced model, you can use
  # params_to_objects "namespace/model"
  def params_to_objects(*names)
    options = names.reject{|o|!o.is_a? Hash} || []
    names = names - options

    first_name = names.shift
    params_to_object(first_name, :id, options)

    names.each do |name|
      safe_name = name.to_s.gsub("/", "_")
      params_to_object(name, "#{safe_name}_id", options)
    end
  end

  def params_to_object(name, id, options)
    safe_name = name.to_s.gsub("/", "_")
    module_eval <<-"end;"
      def set_instance_variable_#{safe_name}
        @#{safe_name} = "#{name.to_s}".classify.constantize[params['#{id.to_s}']] if params['#{id.to_s}']
      end
    end;

    before_filter "set_instance_variable_#{safe_name}".to_sym, *options
  end
end</code></pre>
]]></content:encoded>
			<wfw:commentRss>http://www.flyingmachinestudios.com/2008/09/06/dry-up-controllers-with-params_to_objects/feed/</wfw:commentRss>
		</item>
		<item>
		<title>jquery: Remove Default Text Values on Focus</title>
		<link>http://www.flyingmachinestudios.com/2008/09/01/jquery-remove-default-text-values-on-focus/</link>
		<comments>http://www.flyingmachinestudios.com/2008/09/01/jquery-remove-default-text-values-on-focus/#comments</comments>
		<pubDate>Mon, 01 Sep 2008 22:57:20 +0000</pubDate>
		<dc:creator>Daniel Higginbotham</dc:creator>
		
		<category><![CDATA[Javascript]]></category>

		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.flyingmachinestudios.com/?p=27</guid>
		<description><![CDATA[function remove_defaults(){
  $("input[@type=text]")
    .each(function(){
      this.default_value = this.value
    })
  $("input[@type=text]")
    .focus(function(){
      if(this.value == this.default_value) {
        this.value = ""
      }
    })
 [...]]]></description>
			<content:encoded><![CDATA[<pre><code>function remove_defaults(){
  $("input[@type=text]")
    .each(function(){
      this.default_value = this.value
    })
  $("input[@type=text]")
    .focus(function(){
      if(this.value == this.default_value) {
        this.value = ""
      }
    })
    .end()
}

$(remove_defaults)</code></pre>
]]></content:encoded>
			<wfw:commentRss>http://www.flyingmachinestudios.com/2008/09/01/jquery-remove-default-text-values-on-focus/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
