<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Gem Install That &#187; reidmix</title>
	<atom:link href="http://geminstallthat.wordpress.com/author/reidmix/feed/" rel="self" type="application/rss+xml" />
	<link>http://geminstallthat.wordpress.com</link>
	<description>Ruby on Rails Geek Blog</description>
	<lastBuildDate>Thu, 26 Nov 2009 06:42:05 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<cloud domain='geminstallthat.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://www.gravatar.com/blavatar/871e55c8ac6924b0341dc238eeffe1cc?s=96&#038;d=http://s.wordpress.com/i/buttonw-com.png</url>
		<title>Gem Install That &#187; reidmix</title>
		<link>http://geminstallthat.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://geminstallthat.wordpress.com/osd.xml" title="Gem Install That" />
		<item>
		<title>selectedIndex is your friend on IE6</title>
		<link>http://geminstallthat.wordpress.com/2008/11/05/selectedindex-is-your-friend-on-ie6/</link>
		<comments>http://geminstallthat.wordpress.com/2008/11/05/selectedindex-is-your-friend-on-ie6/#comments</comments>
		<pubDate>Wed, 05 Nov 2008 22:03:22 +0000</pubDate>
		<dc:creator>reidmix</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Example]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[defaultSelected]]></category>
		<category><![CDATA[ie]]></category>
		<category><![CDATA[ie6]]></category>
		<category><![CDATA[ie6 bug]]></category>
		<category><![CDATA[options]]></category>
		<category><![CDATA[select]]></category>
		<category><![CDATA[selected]]></category>
		<category><![CDATA[selectedIndex]]></category>

		<guid isPermaLink="false">http://geminstallthat.wordpress.com/?p=146</guid>
		<description><![CDATA[While working on getting ChainedSelects to work on IE6, I realized there are multiple ways to set an option as selected.  Since ChainedSelects creates all the options for a pre-existing select, I first used the defaultSelected argument passed in the Option constructor:

option = new Option(&#34;name&#34;, &#34;value&#34;, true);

Here, the third argument specifies whether the option is [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=geminstallthat.wordpress.com&blog=309932&post=146&subd=geminstallthat&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>While working on getting <a title="chained_selects on latimes' GitHub" href="http://github.com/latimes/chained_selects/tree/master" target="_blank">ChainedSelects</a> to work on IE6, I realized there are multiple ways to set an option as selected.  Since ChainedSelects creates all the options for a pre-existing select, I first used the <em>defaultSelected</em> argument passed in the Option constructor:</p>
<pre class="brush: jscript;">
option = new Option(&quot;name&quot;, &quot;value&quot;, true);
</pre>
<p>Here, the third argument specifies whether the option is <em>defaultSelected</em>, when the select is first created or the form is reset. This worked fine in Firefox but IE6 blythely ignored it.  So I tried passing a fourth argument that specifies whether the option is currently <em>selected</em>.</p>
<pre class="brush: jscript;">
option = new Option(&quot;name&quot;, &quot;value&quot;, true, true);
</pre>
<p>Again, Firefox does the right thing but IE6 gets wacky and incosistently selects the correct option or sometimes does nothing at all.  It seems as if IE6 misses the &#8220;selected&#8221; message on the event queue, because it works only when i put some <strong>alert()</strong>s in there.</p>
<p>So I tried another way, by using the selected attribute after creating the option:</p>
<pre class="brush: jscript;">
option = new Option(&quot;name&quot;, &quot;value&quot;, true, true);
option.selected = true
</pre>
<p>Again, inconsistent behavior on IE6.  I went to the great oracle and asked google and tried setting the selected attribute to &#8217;selected&#8217;, &#8216;true&#8217;, and &#8216;yes&#8217; all with no luck.  I wonder if this occurs because the select is pre-existing and is not newly created.  This led me to try out the <em>selectedIndex</em> attribute on the select element.</p>
<pre class="brush: jscript;">
select = $('myselect')
select.selectedIndex = 3
</pre>
<p>Bingo!  This works in both Firefox and IE.  The index is 0-based as you would guess (0 is the first option is <strong>select.options</strong>).</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/geminstallthat.wordpress.com/146/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/geminstallthat.wordpress.com/146/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/geminstallthat.wordpress.com/146/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/geminstallthat.wordpress.com/146/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/geminstallthat.wordpress.com/146/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/geminstallthat.wordpress.com/146/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/geminstallthat.wordpress.com/146/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/geminstallthat.wordpress.com/146/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/geminstallthat.wordpress.com/146/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/geminstallthat.wordpress.com/146/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=geminstallthat.wordpress.com&blog=309932&post=146&subd=geminstallthat&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://geminstallthat.wordpress.com/2008/11/05/selectedindex-is-your-friend-on-ie6/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/36b99a20b19e5eb2f2ffd0d74d6b918d?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">reidmix</media:title>
		</media:content>
	</item>
		<item>
		<title>Subselector, Moneypenny</title>
		<link>http://geminstallthat.wordpress.com/2008/11/01/subselector-moneypenny/</link>
		<comments>http://geminstallthat.wordpress.com/2008/11/01/subselector-moneypenny/#comments</comments>
		<pubDate>Sat, 01 Nov 2008 16:59:40 +0000</pubDate>
		<dc:creator>reidmix</dc:creator>
				<category><![CDATA[ActiveRecord]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Database]]></category>
		<category><![CDATA[Example]]></category>
		<category><![CDATA[Monkey Patch]]></category>
		<category><![CDATA[Plugins & Gems]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[bind variables]]></category>
		<category><![CDATA[named bind variables]]></category>
		<category><![CDATA[select]]></category>
		<category><![CDATA[sql]]></category>
		<category><![CDATA[subselect]]></category>

		<guid isPermaLink="false">http://geminstallthat.wordpress.com/?p=137</guid>
		<description><![CDATA[Building on Josh and Damon&#8217;s idea of Hacking a Subselect in ActiveRecord, I wondered if you could bake this kind of functionality into ActiveRecord.  So Doug and I went digging into the rails code, and came up with a plugin that adds subselects to ActiveRecord which we call Subselector.
So far, it only works on the [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=geminstallthat.wordpress.com&blog=309932&post=137&subd=geminstallthat&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Building on <a title="Josh Susser's blog" href="http://blog.hasmanythrough.com/" target="_blank">Josh</a> and <a title="Damon's Blog" href="http://pivotallabs.com/users/damon/blog">Damon</a>&#8217;s idea of <a href="http://pivotallabs.com/users/jsusser/blog/articles/567-hacking-a-subselect-in-activerecord" target="_blank">Hacking a Subselect in ActiveRecord</a>, I wondered if you could bake this kind of functionality into ActiveRecord.  So <a title="Doug McInnes' Blog" href="http://dougmcinnes.com/" target="_self">Doug</a> and I went digging into the rails code, and came up with a plugin that adds subselects to ActiveRecord which we call <a title="Subselector on GitHub" href="http://github.com/latimes/subselector/tree/master" target="_self">Subselector</a>.</p>
<p><span style="text-decoration:line-through;">So far, it only works on the Hash version of conditions.</span></p>
<p>On a column you wish to perform a subselect, pass a hash with <strong>:in</strong>, <strong>:not_in</strong>, <strong>:equals</strong>, or <strong>:not_equals</strong> as the only key.  The value is any of the options you normally would pass to ActiveRecord <strong>find</strong>.  Notice that we make sure to select a single column with the <strong>:select</strong> option:</p>
<pre class="brush: ruby;">
Critic.find(:all, :conditions =&gt; { :id =&gt; {:in =&gt; {:select =&gt; :id, :conditions =&gt; {:active =&gt; true} } } })
</pre>
<p>Although the example may be contrived, here, we are looking for a critics that are in a set of active critics. The SQL:</p>
<pre class="brush: sql;">
select * from critics where id in (select id from critics where active = false)
</pre>
<p>You can see by default it runs the subselect on the table of outer select.  It gets more interesting you want to run a query on another ActiveRecord model:</p>
<pre class="brush: ruby;">
Critic.find(:all, :conditions =&gt; { :id =&gt; {:in =&gt; {:model =&gt; :rankings, :select =&gt; :critic_id, :conditions =&gt;
  {:week =&gt; 39} } } })
</pre>
<p>Here we set <strong>:model</strong> to :rankings.  Rankings is the ActiveRecord model to perform the find, notice we select the :critic_id column, the SQL is:</p>
<pre class="brush: sql;">
select * from critics where id in (select critic_id from rankings where week = 39)
</pre>
<p>And of course you can always just pass a string as a value to the subselect:</p>
<pre class="brush: ruby;">
Critic.find(:all, :conditions =&gt; { :id =&gt; {:not_in =&gt; 'select id from critics where active = true' } })
</pre>
<p>Here&#8217;s how subselector can be used with the <a href="http://pivotallabs.com/users/jsusser/blog/articles/567-hacking-a-subselect-in-activerecord">original example</a>:</p>
<pre class="brush: ruby;">
Post.find(:all, :conditions =&gt; :id =&gt; {:in =&gt; { :select =&gt; :post_id, :conditions =&gt; {:blog_id =&gt; self.id}, <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_surprised.gif' alt=':o' class='wp-smiley' /> rder =&gt; &quot;published_at DESC&quot;, :limit =&gt; options[:limit] || 10, <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_surprised.gif' alt=':o' class='wp-smiley' /> ffset =&gt; options[:offset])} }, <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_surprised.gif' alt=':o' class='wp-smiley' /> rder =&gt; &quot;published_at DESC&quot;)
</pre>
<p><a name="update"></a></p>
<p><strong>UPDATE: Subselector now likes Condition Arrays and Named Bind Variables. </strong></p>
<p>Just pass the hash as a bind variable and specify the type (in/equals) of subselect in the string, make sure to enclose your &#8216;?&#8217; inside parentheses:</p>
<pre class="brush: ruby;">
Critic.find(:all, :conditions =&gt; ['id in (?)', {:select =&gt; :id, :conditions =&gt; 'active = true' }])
Critic.find(:all, :conditions =&gt; ['id not in (?)', {:select =&gt; :id, :conditions =&gt; {:active =&gt; false} }])
Critic.find(:all, :conditions =&gt; ['id in (?)', {:model =&gt; :rankings, :select =&gt; :critic_id, :conditions =&gt; {:week =&gt; 39} }])
</pre>
<p>As you can see, you can format the subselect hash just as above and can specify another model to run the subselect on.  If you prefer to use named bind variable hashes, they still work (yay) as you would expect. And you can assign the subselect using them:</p>
<pre class="brush: ruby;">
Critic.find(:all, :conditions =&gt; ['id in (:subselect)', {:subselect =&gt; {:select =&gt; :id, :conditions =&gt; {:active =&gt; false} } }])
</pre>
<p><strong>UPDATE 2: Now with no ActiveRecord breakage<br />
</strong></p>
<p>We&#8217;ve run the rails ActiveRecord tests without any problems. Let me know if you find any problems.</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/geminstallthat.wordpress.com/137/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/geminstallthat.wordpress.com/137/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/geminstallthat.wordpress.com/137/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/geminstallthat.wordpress.com/137/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/geminstallthat.wordpress.com/137/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/geminstallthat.wordpress.com/137/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/geminstallthat.wordpress.com/137/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/geminstallthat.wordpress.com/137/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/geminstallthat.wordpress.com/137/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/geminstallthat.wordpress.com/137/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=geminstallthat.wordpress.com&blog=309932&post=137&subd=geminstallthat&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://geminstallthat.wordpress.com/2008/11/01/subselector-moneypenny/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/36b99a20b19e5eb2f2ffd0d74d6b918d?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">reidmix</media:title>
		</media:content>
	</item>
		<item>
		<title>These Chains of Selects</title>
		<link>http://geminstallthat.wordpress.com/2008/10/29/these-chains-of-selects/</link>
		<comments>http://geminstallthat.wordpress.com/2008/10/29/these-chains-of-selects/#comments</comments>
		<pubDate>Wed, 29 Oct 2008 22:50:46 +0000</pubDate>
		<dc:creator>reidmix</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Example]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[chained selects]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[JSON]]></category>
		<category><![CDATA[options]]></category>
		<category><![CDATA[Prototype]]></category>
		<category><![CDATA[select]]></category>

		<guid isPermaLink="false">http://geminstallthat.wordpress.com/?p=131</guid>
		<description><![CDATA[I was looking for javascript library that would manage select (HTML) elements that are dependent on one another.  These are the drop-downs you often see on online car sites where you select a make and it populates the next drop-down with the models for that car make.
I was hoping that there would be a libary [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=geminstallthat.wordpress.com&blog=309932&post=131&subd=geminstallthat&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>I was looking for javascript library that would manage select (HTML) elements that are dependent on one another.  These are the drop-downs you often see on online car sites where you select a make and it populates the next drop-down with the models for that car make.</p>
<p>I was hoping that there would be a libary that was publically available, object oriented, small, backed by <a title="Intoducing JSON " href="http://json.org/" target="_blank">JSON</a>, and would even like it to be based on the <a title="Prototype Javascript Library" href="http://www.prototypejs.org/" target="_blank">Prototype</a> library.  All I could find was a library that may satisfy one of my requirements but not all.  Libraries I found were either procedural, terribly bulky and complicated, and never backed by JSON.</p>
<p>In my buy it or build it moment, I decided to build it: here is a <a title="chained_selects on latimes' GitHub" href="http://github.com/latimes/chained_selects/tree/master">chained_selects</a> javascript library.  It&#8217;s fairly lightweight, it runs in about 85 lines (comments and whitespace included), you can initialize it with javascript objects or JSON, it&#8217;s object oriented and relies on just a little bit of Prototype.</p>
<p>You need the heirarchy of data to back a ChainedSelect object, the form, and selects that are assoicated with each &#8220;level&#8221; in the heirarchy.  It can have as many levels you want in the hierarchy from 2 up.  So, in my car example, imagine you have a two car makes (Acura and Volkswagen) and the Acura make has two models (the RL and the TL, sweet!), and the Volkswagen make has three models (Beetle, Jetta, and the Passat).  Each of the models have a database id.  My JSON for this heirarchy would look like:</p>
<pre class="brush: jscript;">
var data = {&quot;Acura&quot;:{&quot;RL&quot;:1, &quot;TL&quot;:2},&quot;Volkswagen&quot;:{&quot;Beetle&quot;:3,&quot;Jetta&quot;:4,&quot;Passat&quot;:5}}
</pre>
<p>You can see the first level is the outer-most hash with the makes, and the inner mosts hashes have the models and their db ids.  For rails programmers, this could be a rails hash that you run to_json with.</p>
<p>I set up my HTML form, with a select for each level in the heirarchy, like so:</p>
<pre class="brush: xml;">
  &lt;form id=&quot;cars&quot; method=&quot;post&quot; action=&quot;/choose_car&quot;&gt;
    &lt;select name=&quot;make&quot;&gt;&lt;/select&gt;
    &lt;select name=&quot;model&quot;&gt;&lt;/select&gt;
  &lt;/form&gt;
</pre>
<p>Then I can setup the ChainedSelect object to manage these selects, using the data above:</p>
<pre class="brush: jscript;">
new ChainedSelect(data, 'cars', ['make','model']);
</pre>
<p>This says, created a chained select with my data for the form with id &#8216;cars&#8217;, with the first level select with the name &#8216;make&#8217; and second level select with the name &#8216;model&#8217;.</p>
<p>The first select will load with three elements:</p>
<ul>
<li>Choose make&#8230;</li>
<li>Acura</li>
<li>Volkswagen</li>
</ul>
<p>When Volkswagen is selected, the second select will load:</p>
<ul>
<li>Choose model&#8230;</li>
<li>Beetle</li>
<li>Jetta</li>
<li>Passat</li>
</ul>
<p>If Acura is then chose, the second select will refresh with the correct data. If the &#8216;model&#8217; is chosen let&#8217;s say Jetta, then the id for that model is sent in the form (4).  For rails developers, the name of the select needs to be different from the label (&#8220;Choose model&#8230;&#8221;), you can specify a label and a select name separately, with an embedded array, like so:</p>
<pre class="brush: jscript;">
new ChainedSelect(data, 'cars', ['make',['car[model]','model']]);
</pre>
<p>Oftentimes, we have an edit page with the values already prefilled on our forms, we can add another array parameter that specifies the path to the selection:</p>
<pre class="brush: jscript;">
new ChainedSelect(data, 'cars', ['make','model'], ['Volkswagen','Jetta']);
</pre>
<p>Lastly, when the final select is chosen, sometimes we want to take an action or an AJAX call, we can supply an onComplete function to run which is yielded a the value chosen:</p>
<pre class="brush: jscript;">
new ChainedSelect(data, 'cars', ['make','model'], null, function(choice) { alert(&quot;You chose:&quot;+choice); } );
</pre>
<p>You can use all of these elements together to get the behavior you want, I also have a little rails form helper to create my javascript for me:</p>
<pre class="brush: ruby;">
  def chained_selects(tree, form, selects, active, oncomplete=nil)
    %(new ChainedSelects(#{tree}, '#{form}', #{selects.inspect}, #{active.inspect}, #{oncomplete || 'null'});)
  end
</pre>
<p>I know that the script can be improved in many ways (<a title="Doug's Page" href="http://dougmcinnes.com/">Doug McInnes</a> added the onComplete feature).  Please feel free to send patches or any bugs you may find.<br />
Enjoy!</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/geminstallthat.wordpress.com/131/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/geminstallthat.wordpress.com/131/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/geminstallthat.wordpress.com/131/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/geminstallthat.wordpress.com/131/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/geminstallthat.wordpress.com/131/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/geminstallthat.wordpress.com/131/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/geminstallthat.wordpress.com/131/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/geminstallthat.wordpress.com/131/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/geminstallthat.wordpress.com/131/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/geminstallthat.wordpress.com/131/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=geminstallthat.wordpress.com&blog=309932&post=131&subd=geminstallthat&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://geminstallthat.wordpress.com/2008/10/29/these-chains-of-selects/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/36b99a20b19e5eb2f2ffd0d74d6b918d?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">reidmix</media:title>
		</media:content>
	</item>
		<item>
		<title>Include Health</title>
		<link>http://geminstallthat.wordpress.com/2008/10/29/include-health/</link>
		<comments>http://geminstallthat.wordpress.com/2008/10/29/include-health/#comments</comments>
		<pubDate>Wed, 29 Oct 2008 16:46:58 +0000</pubDate>
		<dc:creator>reidmix</dc:creator>
				<category><![CDATA[Example]]></category>
		<category><![CDATA[Plugins & Gems]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[big brother]]></category>
		<category><![CDATA[check_health]]></category>
		<category><![CDATA[monitoring]]></category>
		<category><![CDATA[nagios]]></category>
		<category><![CDATA[sa]]></category>
		<category><![CDATA[sysadmin]]></category>

		<guid isPermaLink="false">http://geminstallthat.wordpress.com/?p=117</guid>
		<description><![CDATA[I created a little plugin to make it easier to offer health check URLs in all our applications called Health.  These URLs are a necessity for our SysAdmins to hook into Big Brother or Nagios.  These monitoring systems systematically poll an application at this URL to check the status of the application.
To get started, install [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=geminstallthat.wordpress.com&blog=309932&post=117&subd=geminstallthat&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>I created a little plugin to make it easier to offer health check URLs in all our applications called <a title="Health on latimes' GitHub" href="http://github.com/latimes/health/tree/master" target="_self">Health</a>.  These URLs are a necessity for our SysAdmins to hook into Big Brother or Nagios.  These monitoring systems systematically poll an application at this URL to check the status of the application.</p>
<p>To get started, install the health plugin and include it in your Application controller:</p>
<pre class="brush: ruby;">
class ApplicationController &lt; ActionController::Base
  include Health
end
</pre>
<p>That&#8217;s it.  You should be able to navigate to <a href="http://localhost:3000/check_heath">http://localhost:3000/check_heath</a>. Health sets up the named route &#8216;<span class="s1">check_health&#8217; and</span> by default it will check the connection of the database by running a &#8220;<strong>select 1</strong>&#8221; SQL statement.  If all goes well you should see &#8220;SERVERUP&#8221;.  If there&#8217;s a problem with the query you will see &#8220;DBDOWN&#8221; or an 500 error depending on the level of problem.  You can turn off the DB checking (our SysAdmins wanted it):</p>
<pre class="brush: ruby;">
ApplicationController &lt; ActionController::Base
  include Health
  health_check :with_db =&gt; false
end
</pre>
<p>One more trick, it does is handle any additional / custom checks that you may require.  Pass a block, Proc, or a symbol that represents the name of the method to the health_check directive:</p>
<pre class="brush: ruby;">
ApplicationController &lt; ActionController::Base
  include Health
  health_check do |controller|
    controller.has_donut? || &quot;no donut&quot;
  end
end
</pre>
<p>In this case, assuming the controller has a method called has_donut? which does not return <strong>false</strong> or <strong>nil</strong>, you will see the &#8220;SERVERUP&#8221; message, otherwise you will see what was last evaluated in a message like &#8220;PROCDOWN no donut&#8221;</p>
<p>And you can mix and match all three types of blocks, Procs, and symbols &#8212; more examples are in the <a title="Health's Read Me " href="http://github.com/latimes/health/tree/master/README" target="_self">README</a>.</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/geminstallthat.wordpress.com/117/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/geminstallthat.wordpress.com/117/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/geminstallthat.wordpress.com/117/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/geminstallthat.wordpress.com/117/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/geminstallthat.wordpress.com/117/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/geminstallthat.wordpress.com/117/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/geminstallthat.wordpress.com/117/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/geminstallthat.wordpress.com/117/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/geminstallthat.wordpress.com/117/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/geminstallthat.wordpress.com/117/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=geminstallthat.wordpress.com&blog=309932&post=117&subd=geminstallthat&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://geminstallthat.wordpress.com/2008/10/29/include-health/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/36b99a20b19e5eb2f2ffd0d74d6b918d?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">reidmix</media:title>
		</media:content>
	</item>
		<item>
		<title>Plug This: css_browser_selector plugin</title>
		<link>http://geminstallthat.wordpress.com/2008/05/22/plug-this-css_browser_selector-plugin/</link>
		<comments>http://geminstallthat.wordpress.com/2008/05/22/plug-this-css_browser_selector-plugin/#comments</comments>
		<pubDate>Thu, 22 May 2008 19:24:34 +0000</pubDate>
		<dc:creator>reidmix</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Plugins & Gems]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[Announcement]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[plugin]]></category>

		<guid isPermaLink="false">http://geminstallthat.wordpress.com/?p=35</guid>
		<description><![CDATA[I&#8217;m happy to announce my first plugin based on the css_browser_selector javascript which adds the name of the browser and platform as css class selectors that your client is using on the html element in your page. For example:

&#60;html class=&#34;gecko mac js&#34;&#62;

I&#8217;ve released my first version of the plugin (at 0.9.1) and you can download [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=geminstallthat.wordpress.com&blog=309932&post=35&subd=geminstallthat&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>I&#8217;m happy to announce my first plugin based on the <a title="css_browser_selector homepage" href="http://rafael.adm.br/css_browser_selector/" target="_blank">css_browser_selector</a> javascript which adds the name of the browser and platform as css class selectors that your client is using on the <strong>html</strong> element in your page. For example:</p>
<pre class="brush: xml;">
&lt;html class=&quot;gecko mac js&quot;&gt;
</pre>
<p>I&#8217;ve released my first version of the plugin (at 0.9.1) and you can <a title="css_browser_selector plugin" href="http://latimes.rubyforge.org/svn/plugins/css_browser_selector/" target="_self">download it  from on LATimes RubyForge project</a> or from <a title="css_browser_selector on latimes' GitHub" href="http://github.com/latimes/css_browser_selector/tree/master">GitHub</a>.  You can read how to use the plugin in its <a title="css_browser_selector readme" href="http://latimes.rubyforge.org/svn/plugins/css_browser_selector/trunk/README">README</a>, it offers a way to include the javascript inline into your views and layouts:</p>
<pre class="brush: ruby;">
&lt;%= javascript_tag css_browser_selector %&gt;
</pre>
<p>But wait there&#8217;s more!  What the plugin also does is offer a <strong>body</strong> (and <strong>html</strong>) tag helper that will render css selectors into your views from the backend. The real benefit to this is that these selectors will be available within the page <em>without</em> needing javascript enabled:</p>
<pre class="brush: ruby;">
&lt;% body do %&gt;
  &lt;%= yield %&gt;
&lt;% end %&gt;
</pre>
<p>And this will add the selectors as you would expect to your body tag:</p>
<pre class="brush: xml;">
&lt;body class=&quot;gecko mac&quot;&gt;
</pre>
<p>The body helper is currently aware of page caching and will revert to the javascript version if the page is being cached through the <strong>caches_page</strong> method.</p>
<p>This is my first plugin and, yes, I still have some work to do (complete my tests, better caching awareness, sensitivity to pre-existing body and html tag helpers), but I wanted to share back to the community.  Following <a title="Gile's blog-a-rama" href="http://gilesbowkett.blogspot.com/">Giles Bowkett</a>&#8217;s mantra to release software (often and early).</p>
<p>There&#8217;s plenty of more options as explained by the README.  I welcome feedback, suggestions, improvements, bugs, and diffs! I&#8217;d also like to thank <a title="Rafeal's Blog-a-rama" href="http://rafael.adm.br/">Rafeal Lima</a> who implemented and maintains the javascript and his help and <a title="css_browswer_selector for Rails fans" href="http://rafael.adm.br/p/css-browser-selector-for-rails-fans/">support</a> with the plugin</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/geminstallthat.wordpress.com/35/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/geminstallthat.wordpress.com/35/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/geminstallthat.wordpress.com/35/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/geminstallthat.wordpress.com/35/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/geminstallthat.wordpress.com/35/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/geminstallthat.wordpress.com/35/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/geminstallthat.wordpress.com/35/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/geminstallthat.wordpress.com/35/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/geminstallthat.wordpress.com/35/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/geminstallthat.wordpress.com/35/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/geminstallthat.wordpress.com/35/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/geminstallthat.wordpress.com/35/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=geminstallthat.wordpress.com&blog=309932&post=35&subd=geminstallthat&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://geminstallthat.wordpress.com/2008/05/22/plug-this-css_browser_selector-plugin/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/36b99a20b19e5eb2f2ffd0d74d6b918d?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">reidmix</media:title>
		</media:content>
	</item>
		<item>
		<title>IE6 Accept Header is Faulty and Makes format.any Suck</title>
		<link>http://geminstallthat.wordpress.com/2008/05/14/ie6-accept-header-is-faulty/</link>
		<comments>http://geminstallthat.wordpress.com/2008/05/14/ie6-accept-header-is-faulty/#comments</comments>
		<pubDate>Wed, 14 May 2008 17:01:29 +0000</pubDate>
		<dc:creator>reidmix</dc:creator>
				<category><![CDATA[AbstractRequest]]></category>
		<category><![CDATA[ActionController]]></category>
		<category><![CDATA[Changeset]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Example]]></category>
		<category><![CDATA[MimeResponds]]></category>
		<category><![CDATA[Monkey Patch]]></category>
		<category><![CDATA[Plugins & Gems]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[acts_as_authenticated]]></category>
		<category><![CDATA[Accept Header]]></category>
		<category><![CDATA[Any]]></category>
		<category><![CDATA[Format]]></category>
		<category><![CDATA[Format.any]]></category>
		<category><![CDATA[HTTP_ACCEPT]]></category>
		<category><![CDATA[ie]]></category>
		<category><![CDATA[ie bug]]></category>
		<category><![CDATA[ie6]]></category>
		<category><![CDATA[ie6 bug]]></category>
		<category><![CDATA[internet explorer]]></category>
		<category><![CDATA[internet explorer 6]]></category>

		<guid isPermaLink="false">http://geminstallthat.wordpress.com/?p=33</guid>
		<description><![CDATA[I&#8217;ve been using the awesome acts_as_authenticated plugin as the basis for user login and authorization.  Its access_denied method takes advantage of the ActionController::MimeResponds.any method which will be invoked on a login_required before filter:

    def access_denied
      respond_to do &#124;format&#124;
        format.html [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=geminstallthat.wordpress.com&blog=309932&post=33&subd=geminstallthat&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>I&#8217;ve been using the awesome <a title="acts_as_authenticated wiki page at rubyonrails" href="http://wiki.rubyonrails.org/rails/pages/Acts_as_authenticated">acts_as_authenticated</a> plugin as the basis for user login and authorization.  Its <strong>access_denied</strong> method takes advantage of the <strong>ActionController::MimeResponds.any</strong> method which will be invoked on a <strong>login_required</strong> before filter:</p>
<pre class="brush: ruby;">
    def access_denied
      respond_to do |format|
        format.html do
          store_location
          redirect_to new_session_path
        end
        format.any do
          request_http_basic_authentication 'Web Password'
        end
      end
    end
</pre>
<p>This code essentially says, if it&#8217;s an html request, store the original request and redirect to the login page, any other requests get the 401 Unauthorized header which the user agent can then use to initiate an HTTP Auth.  This bit of code only works correctly with Edge Rail&#8217;s <a title="Rails Changeset 8987" href="http://dev.rubyonrails.org/changeset/8987">8987 Changeset</a> that allows any to act as a <a title="Rails Ticket #11140" href="http://dev.rubyonrails.org/ticket/11140">catch-all for any request mime-types not already specified</a>.</p>
<p><em>Awesome!</em><br />
Except when Internet Explorer 6 comes into the picture and happily sends this<br />
<a title="Intermittent IE failures" href="http://intertwingly.net/blog/2007/08/23/Intermittent-IE-failures">strange</a> and <a title="IEBlog where users request complete headers" href="http://blogs.msdn.com/ie/archive/2005/07/29/445242.aspx">incomplete</a> <strong>&#8216;Accept:&#8217;</strong> header:</p>
<p><code>image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*</code></p>
<p>As you can see, it doesn&#8217;t specify <strong>application/xhtml+xml</strong> or even <strong>text/html</strong> and what&#8217;s worse is the subsequent requests to the same page sends the catch-all <strong>*/*</strong>.</p>
<p><em>What does this all mean?</em><br />
When IE6 navigates to a page that requires login, instead of redirecting the user to the login page, the user is presented with an HTTP Auth Dialog.  What&#8217;s worse is that in my application, cookies and other application state for an web-based end-user is set outside of the <strong>login_from_basic_auth</strong> method &#8212; you know &#8212; in my login action.</p>
<p style="text-align:center;"><img style="border:1px solid black;margin:5px;" src="http://geminstallthat.files.wordpress.com/2008/05/httpauth.jpg" alt="HTTP Auth Prompt by IE6" /></p>
<p>My guess is when the <strong>format.any</strong> fix goes out in the next rails release, IE6 users on <strong> acts_as_authenticated</strong> sites are going to be sad-faced.  I&#8217;m not entirely sure the correct way to fix this problem but this is how I solved it in my application:</p>
<pre class="brush: ruby;">
class ActionController::AbstractRequest
  def accepts_with_faulty_header
    @env['HTTP_ACCEPT']='*/*' if @env['HTTP_USER_AGENT'] =~ /msie/i and @env['HTTP_USER_AGENT'] !~ /opera|webtv/i
    accepts_without_faulty_header
  end
  alias_method_chain :accepts, :faulty_header
end
</pre>
<p>Originally, I thought to patch the <strong>Mime::Type.parse</strong> function, but decided that I wanted to make sure to look at the user agent for IE6.  As you can see, I switch the <strong>HTTP_ACCEPT</strong> header to the catch-all <strong>*/*</strong> string  if the<span style="text-decoration:line-through;"> original <strong>HTTP_ACCEPT</strong> header is a match to the exact (bizarre) IE6 string and the</span> <strong>HTTP_USER_AGENT</strong> is IE (matches MSIE but not Opera or WebTV). Then I call the original <strong>ActionController::AbstractRequest.accepts</strong> method.</p>
<p>I&#8217;d love to hear your ideas and suggestions &#8212; and if others have run into this problem as I didn&#8217;t find many users have this exact problem and how they may have solved it.</p>
<p>Update: Based on the conversation in the comments, I&#8217;ve re-written the patch to always change the HTTP_ACCEPT header to the catch-all <strong>*/*</strong> if it is an IE Browser.</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/geminstallthat.wordpress.com/33/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/geminstallthat.wordpress.com/33/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/geminstallthat.wordpress.com/33/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/geminstallthat.wordpress.com/33/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/geminstallthat.wordpress.com/33/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/geminstallthat.wordpress.com/33/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/geminstallthat.wordpress.com/33/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/geminstallthat.wordpress.com/33/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/geminstallthat.wordpress.com/33/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/geminstallthat.wordpress.com/33/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/geminstallthat.wordpress.com/33/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/geminstallthat.wordpress.com/33/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=geminstallthat.wordpress.com&blog=309932&post=33&subd=geminstallthat&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://geminstallthat.wordpress.com/2008/05/14/ie6-accept-header-is-faulty/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/36b99a20b19e5eb2f2ffd0d74d6b918d?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">reidmix</media:title>
		</media:content>

		<media:content url="http://geminstallthat.files.wordpress.com/2008/05/httpauth.jpg" medium="image">
			<media:title type="html">HTTP Auth Prompt by IE6</media:title>
		</media:content>
	</item>
		<item>
		<title>Use ActiveResource to Consume Simple Objects Over REST</title>
		<link>http://geminstallthat.wordpress.com/2008/01/16/use-activeresource-to-consume-any-object-over-rest/</link>
		<comments>http://geminstallthat.wordpress.com/2008/01/16/use-activeresource-to-consume-any-object-over-rest/#comments</comments>
		<pubDate>Thu, 17 Jan 2008 06:43:44 +0000</pubDate>
		<dc:creator>reidmix</dc:creator>
				<category><![CDATA[ActiveResource]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Example]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[REST]]></category>

		<guid isPermaLink="false">http://geminstallthat.wordpress.com/2008/01/16/use-activeresource-to-consume-any-object-over-rest/</guid>
		<description><![CDATA[I&#8217;m sure that many organizations have services available via REST that are not produced by Rails and do not follow Rails conventions.  That doesn&#8217;t mean you have to write your own client.  For simple objects, use ActiveResource.
To take advantage of ActiveResource in this way use the ActiveResource::Base#find method. You need to find(:all), find(:first), [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=geminstallthat.wordpress.com&blog=309932&post=24&subd=geminstallthat&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>I&#8217;m sure that many organizations have services available via REST that are not produced by Rails and do not follow Rails conventions.  That doesn&#8217;t mean you have to write your own client.  For simple objects, use ActiveResource.</p>
<p>To take advantage of ActiveResource in this way use the <b>ActiveResource::Base#find</b> method. You need to <b>find(:all)</b>, <b>find(:first)</b>, or <b>find(:one)</b> but you need to pass a string of the path to the :from option along with any <b>:params</b> you need.  If you pass a symbol as the <b>:from</b> option, this will not work and will employ all of the the <b>ActiveResource::Base</b> mechanics. A string will bypass this, for example:</p>
<pre class="brush: ruby;">
class RestClient &lt; ActiveResource::Base
  self.site = &quot;http://java-based-service.company.com&quot;

  def self.invoke(params = {})
    find(:one, :from =&gt; &quot;/nonconventional/path/to/rest/service/&quot;, :params =&gt; params)
  end
end

object = RestClient.invoke(:irregular_id =&gt; 10) #=&gt; service returns &lt;data&gt;&lt;name&gt;reid&lt;/name&gt;&lt;role&gt;blogger&lt;/role&gt;&lt;/data&gt;
object.name #=&gt; reid
object.role #=&gt; blogger
</pre>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/geminstallthat.wordpress.com/24/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/geminstallthat.wordpress.com/24/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/geminstallthat.wordpress.com/24/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/geminstallthat.wordpress.com/24/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/geminstallthat.wordpress.com/24/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/geminstallthat.wordpress.com/24/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/geminstallthat.wordpress.com/24/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/geminstallthat.wordpress.com/24/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/geminstallthat.wordpress.com/24/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/geminstallthat.wordpress.com/24/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/geminstallthat.wordpress.com/24/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/geminstallthat.wordpress.com/24/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=geminstallthat.wordpress.com&blog=309932&post=24&subd=geminstallthat&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://geminstallthat.wordpress.com/2008/01/16/use-activeresource-to-consume-any-object-over-rest/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/36b99a20b19e5eb2f2ffd0d74d6b918d?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">reidmix</media:title>
		</media:content>
	</item>
		<item>
		<title>Passing Hashes to Partials</title>
		<link>http://geminstallthat.wordpress.com/2007/09/13/passing-hashes-to-partials/</link>
		<comments>http://geminstallthat.wordpress.com/2007/09/13/passing-hashes-to-partials/#comments</comments>
		<pubDate>Thu, 13 Sep 2007 17:42:33 +0000</pubDate>
		<dc:creator>reidmix</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Example]]></category>
		<category><![CDATA[Hash]]></category>
		<category><![CDATA[Partial]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[SimpleDelegator]]></category>

		<guid isPermaLink="false">http://geminstallthat.wordpress.com/2007/09/13/passing-hashes-to-partials/</guid>
		<description><![CDATA[Sometimes you need to pass a Hash or collection of Hashes to a partial.  In either case, when render tries to determine if you are using the old style method (render_partial) or the new style.  When it comes across your hash, rails believes it&#8217;s dealing with all your supplied parameters to   [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=geminstallthat.wordpress.com&blog=309932&post=12&subd=geminstallthat&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Sometimes you need to pass a <strong>Hash</strong> or collection of <strong>Hash</strong>es to a partial.  In either case, when <strong>render</strong> tries to determine if you are using the old style method (<strong>render_partial</strong>) or the new style.  When it comes across your hash, rails believes it&#8217;s dealing with all your supplied parameters to   <strong>render</strong>.  You can see this logic in <strong>action_view/partials.rb</strong>:</p>
<pre class="brush: ruby;">
module ActionView
	module Partials
		def render_partial(partial_path, local_assigns = nil, deprecated_local_assigns = nil) #:nodoc:
			path, partial_name = partial_pieces(partial_path)
			object = extracting_object(partial_name, local_assigns, deprecated_local_assigns)
			local_assigns = extract_local_assigns(local_assigns, deprecated_local_assigns)
			local_assigns = local_assigns ? local_assigns.clone : {}
			...
		end
	end
end
</pre>
<p>You can see the last line shown in the method, where if it can&#8217;t determine a local_assigns, it just uses an empty <strong>Hash</strong>.  And so that&#8217;s how it surfaces, you pass your <strong>Hash</strong> to the partial and nothing gets rendered.  What we need to do is disguise that we are passing a <strong>Hash</strong> but have all the functionality of one.</p>
<p>Ruby gives us a few options but the easiest is <strong>SimpleDelegator</strong>.   All we need to do is pass our object upon initialization and <strong>SimpleDelegator</strong> will delegate all methods to that object:</p>
<pre class="brush: ruby;">
myhash = { :a =&gt; "test1", :b =&gt; "test2" }
d = SimpleDelegator.new(myhash)
puts d[:a] # =&gt; test1
</pre>
<p>If sometimes have collections of <strong>Hash</strong>es (or <strong>Hash</strong>es mixed in with my collection), I employ the following pattern:</p>
<pre class="brush: ruby;">
collection = [collection] unless collection.is_a? Array
collection = collection.collect { |i| (i.is_a? Hash) ? SimpleDelegator.new(i) : i }
render :partial =&gt; "mypartial", <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_surprised.gif' alt=':o' class='wp-smiley' /> bject =&gt; collection.compat
</pre>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/geminstallthat.wordpress.com/12/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/geminstallthat.wordpress.com/12/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/geminstallthat.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/geminstallthat.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/geminstallthat.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/geminstallthat.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/geminstallthat.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/geminstallthat.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/geminstallthat.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/geminstallthat.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/geminstallthat.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/geminstallthat.wordpress.com/12/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=geminstallthat.wordpress.com&blog=309932&post=12&subd=geminstallthat&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://geminstallthat.wordpress.com/2007/09/13/passing-hashes-to-partials/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/36b99a20b19e5eb2f2ffd0d74d6b918d?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">reidmix</media:title>
		</media:content>
	</item>
		<item>
		<title>Patching Capistrano to use CVS over SSH</title>
		<link>http://geminstallthat.wordpress.com/2007/09/11/patching-capistrano-to-use-cvs-over-ssh/</link>
		<comments>http://geminstallthat.wordpress.com/2007/09/11/patching-capistrano-to-use-cvs-over-ssh/#comments</comments>
		<pubDate>Tue, 11 Sep 2007 22:10:18 +0000</pubDate>
		<dc:creator>reidmix</dc:creator>
				<category><![CDATA[CVS]]></category>
		<category><![CDATA[Capistrano]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Command Line]]></category>
		<category><![CDATA[Monkey Patch]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[SSH]]></category>

		<guid isPermaLink="false">http://geminstallthat.wordpress.com/2007/09/11/patching-capistrano-to-use-cvs-over-ssh/</guid>
		<description><![CDATA[At work we still use CVS as our versioning repository and most of our systems rely on CVS to build and deploy into production.  Currently there is no effort to transition to SVN, so we need to develop a patch to Capistrano to allow our projects to deploy to our development lab.  We [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=geminstallthat.wordpress.com&blog=309932&post=11&subd=geminstallthat&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>At work we still use CVS as our versioning repository and most of our systems rely on CVS to build and deploy into production.  Currently there is no effort to transition to SVN, so we need to develop a patch to Capistrano to allow our projects to deploy to our development lab.  We needed to extend Capistrano handle SSH logins to CVS and handle CVS repository directories.</p>
<p>Overall, both changes needed to be applied to the <strong>checkout</strong> method in Capistrano&#8217;s <strong>Cvs</strong> class.</p>
<p>We use SSH as the underlying communication mechanism for CVS but there is a difference in the password prompt: SSH&#8217;s is capitalized.  We just need to make the prompt check case insensitive with the i switch:</p>
<pre class="brush: ruby;">if out =~ %r{password:}i</pre>
<p>When setting up Capistrano (v1.4) for use in our development lab, the <strong>:application</strong> configuration is not sufficient to identify our rails project the CVS tree.  We are not cool enough to setup or use modules to map into our repository directories, so our projects are usually in some form of <strong>webdev/project/appname</strong>.  To handle this, i create an additional configuration parameter called <strong>:project</strong> in the <strong>deploy.rb</strong>:</p>
<pre class="brush: ruby;">set :project, "cvs/dir/to/myproj"</pre>
<p>And we no longer use the application name for the CVS path, we use the project variable:</p>
<pre class="brush: ruby;">
project = configuration[:project] || actor.application
command = &amp;lt;&amp;lt;-CMD
  cd #{configuration.releases_path};
  CVS_RSH="#{cvs_rsh}" #{cvs} -d #{configuration.repository} -Q #{op} -D "#{configuration.revision}" #{branch_option} -d #{File.basename(actor.release_path)} #{project};
CMD
</pre>
<p>The hardest part is patching Capistrano.  Capistrano&#8217;s code gets loaded well after any library or environment gets loaded.  The trick is to use the <strong>method_added</strong> hook to wait for the checkout method to get loaded and then alias the method to the patched one, we need to keep a variable around to check if we&#8217;ve patched the method so we don&#8217;t end up in an infinite loop:</p>
<pre class="brush: ruby;">
@@checkout_patched = false
def Cvs.method_added(id)
  if id.id2name == "checkout"
    unless @@checkout_patched
      @@checkout_patched = true
      alias_method :checkout, :checkout_patch
    end
  end
end
</pre>
<p>I&#8217;ve not checked to see how these changes work or differ in Capistrano 2. But with all these elements together using Capistrano v1.4, I can drop this file in my <strong>lib</strong> directory or create a plugin with it.  Together, here is the full patch which I have in a file called <strong>capistrano_cvs_ext.rb</strong>:</p>
<pre class="brush: ruby;">
module Capistrano
  module SCM
    class Cvs &amp;lt; Base
      @@checkout_patched = false
      def Cvs.method_added(id)
        if id.id2name == "checkout"
          unless @@checkout_patched
            @@checkout_patched = true
            alias_method :checkout, :checkout_patch
          end
        end
      end

      def checkout_patch(actor)
        cvs = configuration[:cvs] || "cvs"
        cvs_rsh = configuration[:cvs_rsh] || ENV['CVS_RSH'] || "ssh"

        if "HEAD" == configuration.branch then
            branch_option = ""
        else
            branch_option = "-r #{configuration.branch}"
        end

        # cvs has a root and repository, repository is not the same as application name as it can be a path
        op = configuration[:checkout] || "co"
        project = configuration[:project] || actor.application

        command = &amp;lt;&amp;lt;-CMD
          cd #{configuration.releases_path};
          CVS_RSH="#{cvs_rsh}" #{cvs} -d #{configuration.repository} -Q #{op} -D "#{configuration.revision}" #{branch_option} -d #{File.basename(actor.release_path)} #{project};
        CMD

        run_checkout(actor, command) do |ch, stream, out|
          prefix = "#{stream} :: #{ch[:host]}"
          actor.logger.info out, prefix
          if out =~ %r{password:}i  # SSH asks for "Password" with a capital P
            actor.logger.info "CVS is asking for a password", prefix
            ch.send_data "#{actor.password}n"
          elsif out =~ %r{^Enter passphrase}
            message = "CVS needs your key's passphrase and cannot proceed"
            actor.logger.info message, prefix
            raise message
          end
        end
      end
    end
  end
end
</pre>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/geminstallthat.wordpress.com/11/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/geminstallthat.wordpress.com/11/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/geminstallthat.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/geminstallthat.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/geminstallthat.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/geminstallthat.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/geminstallthat.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/geminstallthat.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/geminstallthat.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/geminstallthat.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/geminstallthat.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/geminstallthat.wordpress.com/11/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=geminstallthat.wordpress.com&blog=309932&post=11&subd=geminstallthat&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://geminstallthat.wordpress.com/2007/09/11/patching-capistrano-to-use-cvs-over-ssh/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/36b99a20b19e5eb2f2ffd0d74d6b918d?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">reidmix</media:title>
		</media:content>
	</item>
	</channel>
</rss>