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

<channel>
	<title>Duplo &#187; Rails</title>
	<atom:link href="http://kill-0.com/duplo/tag/rails/feed/" rel="self" type="application/rss+xml" />
	<link>http://kill-0.com/duplo</link>
	<description>Building Blocks &#38; Learning Experiences</description>
	<lastBuildDate>Fri, 05 Aug 2011 15:30:11 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>My tweaks to metric_fu&#8217;s saikuro and flay configurations</title>
		<link>http://kill-0.com/duplo/2010/02/09/my-tweaks-to-metric_fus-saikuro-and-flay-configurations/</link>
		<comments>http://kill-0.com/duplo/2010/02/09/my-tweaks-to-metric_fus-saikuro-and-flay-configurations/#comments</comments>
		<pubDate>Wed, 10 Feb 2010 06:26:01 +0000</pubDate>
		<dc:creator>ericw</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[metric_fu]]></category>
		<category><![CDATA[saikuro]]></category>

		<guid isPermaLink="false">http://kill-0.com/duplo/?p=91</guid>
		<description><![CDATA[In the process of setting up metric_fu, I found that, one way or another, saikuro&#8217;s output wasn&#8217;t getting into the correct place. I&#8217;ll spare you the long story, and just show the config settings I had to put into my Rakefile to get things working: config.saikuro = { &#58;output_directory => "#{ENV["CC_BUILD_ARTIFACTS"]}/scratch/saikuro", :input_directory => ["app\" --input_directory [...]]]></description>
			<content:encoded><![CDATA[<p>In the process of setting up metric_fu, I found that, one way or another, saikuro&#8217;s output wasn&#8217;t getting into the correct place.  I&#8217;ll spare you the long story, and just show the config settings I had to put into my Rakefile to get things working:<br />
<code>
<pre>config.saikuro = {
<b>  &#58;output_directory => "#{ENV["CC_BUILD_ARTIFACTS"]}/scratch/saikuro", </b>
<b>  :input_directory => ["app\" --input_directory \"lib"],</b>
  :cyclo => "",
  :filter_cyclo => "0",
  :warn_cyclo => "5",
  :error_cyclo => "7",
  :formater => "text", #this needs to be set to "text"
}
config.flay = {
  :dirs_to_flay => ['app', 'lib',],
<b>  :minimum_score => 10, </b>
}
</pre>
<p></code><br />
My changes in bold.</p>
]]></content:encoded>
			<wfw:commentRss>http://kill-0.com/duplo/2010/02/09/my-tweaks-to-metric_fus-saikuro-and-flay-configurations/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Rspec 1.1.4 and Helper spec woes</title>
		<link>http://kill-0.com/duplo/2008/08/06/rspec-114-and-helper-spec-woes/</link>
		<comments>http://kill-0.com/duplo/2008/08/06/rspec-114-and-helper-spec-woes/#comments</comments>
		<pubDate>Thu, 07 Aug 2008 04:11:57 +0000</pubDate>
		<dc:creator>ericw</dc:creator>
				<category><![CDATA[mildred]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[1.1.4]]></category>
		<category><![CDATA[helper]]></category>
		<category><![CDATA[rspec]]></category>
		<category><![CDATA[spec]]></category>

		<guid isPermaLink="false">http://kill-0.com/duplo/2008/08/06/rspec-114-and-helper-spec-woes/</guid>
		<description><![CDATA[I was having all sorts of problems upgrading Mildred to Rails 2.1.  A lot of the errors I was seeing were like the following: ArgumentError in 'TracksController downloading a track by admin should not be a redirection' wrong number of arguments (0 for 1) /Users/ewollesen/src/mildred/app/models/track.rb:52:in `title' /Users/ewollesen/src/mildred/app/models/track.rb:52:in `filename' /Users/ewollesen/src/mildred/app/controllers/tracks_controller.rb:49:in `download' ./spec/controllers/tracks_controller_spec.rb:82: It took me a [...]]]></description>
			<content:encoded><![CDATA[<p>I was having all sorts of problems upgrading Mildred to Rails 2.1.  A lot of the errors I was seeing were like the following:</p>
<pre><code>ArgumentError in 'TracksController downloading a track by admin should not be a redirection'
wrong number of arguments (0 for 1)
/Users/ewollesen/src/mildred/app/models/track.rb:52:in `title'
/Users/ewollesen/src/mildred/app/models/track.rb:52:in `filename'
/Users/ewollesen/src/mildred/app/controllers/tracks_controller.rb:49:in `download'
./spec/controllers/tracks_controller_spec.rb:82:</code></pre>
<p>It took me a good while to figure out what was going on.  The error was strange because as far as I knew, <code>title</code> was a database attribute in the Album model, which was a descendant of ActiveRecord.  There shouldn&#8217;t have been any arguments required.  Indeed, firing up my debugger and running <code>track.album.read_attribute(:title)</code> returned the expected result of &#8220;Test Album 1&#8243;.  I was very puzzled.</p>
<p>I realized that my title method was being overridden, but by what?  I started feeding the title method random arguments in the hopes of learning something new.  It wasn&#8217;t long before I got lucky:</p>
<pre><code>(rdb:1) e track.album.title("x")
NoMethodError Exception: undefined method `content_tag' for #&lt;Album:0x3d5bbfc&gt;</code></pre>
<p>That tipped me off as to what was overriding my title method.  The <code>content_for</code> is part of a pattern I use to set a view&#8217;s title in the layout via a method called <code>title</code> in my <a href="http://www.xmtp.net/websvn/filedetails.php?repname=mildred&amp;path=%2Fmildred_rails%2Fbranches%2Frails-2.1%2Fapp%2Fhelpers%2Fapplication_helper.rb&amp;rev=552&amp;sc=0"><code>ApplicationHelper</code></a>.  This made me think of how in Rspec 1.1.4, a Helper module is no longer included by default.  I popped over to my <a href="http://www.xmtp.net/websvn/filedetails.php?repname=mildred&amp;path=%2Fmildred_rails%2Fbranches%2Frails-2.1%2Fspec%2Fhelpers%2Fapplication_helper_spec.rb&amp;rev=0&amp;sc=0"><code>application_helper_spec.rb</code></a> and found something similar to this:</p>
<pre><code>require File.dirname(__FILE__) + '/../spec_helper'

include ApplicationHelper

describe "ApplicationHelper" do</code></pre>
<p>This needed to be changed to:</p>
<pre><code>require File.dirname(__FILE__) + '/../spec_helper'

describe "ApplicationHelper" do

  include ApplicationHelper</code></pre>
<p>Then all was well.  Whew.  Just to be sure I didn&#8217;t run into this sort of thing again, I went ahead and made sure that all of my other Helper specs followed this paradigm.</p>
<p>This is the second time I&#8217;ve run into an issue where RSpec had overridden some seemingly random method in some seemingly random object.  I guess there&#8217;s a lot of magic in there that I don&#8217;t have my head wrapped around yet.  I just wish it were easier to spot!</p>
]]></content:encoded>
			<wfw:commentRss>http://kill-0.com/duplo/2008/08/06/rspec-114-and-helper-spec-woes/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>JavaScript Conditionals from ERb</title>
		<link>http://kill-0.com/duplo/2008/05/01/javascript-conditionals-from-erb/</link>
		<comments>http://kill-0.com/duplo/2008/05/01/javascript-conditionals-from-erb/#comments</comments>
		<pubDate>Fri, 02 May 2008 04:57:45 +0000</pubDate>
		<dc:creator>ericw</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://kill-0.com/duplo/2008/05/01/javascript-conditionals-from-erb/</guid>
		<description><![CDATA[Rails&#8217;s JavaScript generator provides some great functionality. But unfortunately, one of the things it can&#8217;t do for you, is generate JavaScript conditionally, based on the page&#8217;s content. The reason is simply that the page&#8217;s content doesn&#8217;t exist at the time the conditional in your code was executed. I wanted to do something like the following: [...]]]></description>
			<content:encoded><![CDATA[<p>Rails&#8217;s <a href="http://api.rubyonrails.com/classes/ActionView/Helpers/PrototypeHelper/JavaScriptGenerator/GeneratorMethods.html">JavaScript generator</a> provides some great functionality.  But unfortunately, one of the things it can&#8217;t do for you, is generate JavaScript conditionally, based on the page&#8217;s content.  The reason is simply that the page&#8217;s content doesn&#8217;t exist at the time the conditional in your code was executed.  I wanted to do something like the following:</p>
<pre><code>if page["album_1_rating"]
  page["album_1_rating"].visual_effect(:highlight)
end</code></pre>
<p>As I said, at the time the <tt>if</tt> statement above is executed, there is no HTML file yet, so the generator can&#8217;t possibly know if the element referenced will exist in the file or not.  In fact, <tt>page["album_1_rating"]</tt> is a <tt>ActionView::Helpers::JavaScriptElementProxy</tt> object, which is not false, so the <tt>if</tt> statement will always execute.  This wasn&#8217;t what I wanted.  So I came up with something that would work. I added the following method to <tt>lib/prototype_helper_hacks.rb</tt>, then required it in <tt>config/environment.rb</tt>.</p>
<pre><code>def if_element(id, &amp;block)
  self &lt;&lt; "if ($(\"#{id}\")) {"
  block.call(self[id])
  self &lt;&lt; "}"
end</code></pre>
<p>This lets me do things like this in my views:</p>
<pre><code>page.if_element("album_1_rating") do |element|
  element.visual_effect(:highlight)
end</code></pre>
<p>That made me happy.</p>
<p>In thinking more about the situation, I&#8217;m not sure this is really such a great method.  It works, but I can&#8217;t help but feel there&#8217;s some better way of going about this.  I could simply use the page append method, to do something like:</p>
<pre><code>page &lt;&lt; "if ($(id)) {"
  page["album_1_rating"].visual_effect(:highlight)
page &lt;&lt; "}"</code></pre>
<p>But at least if nothing else, my <tt>if_element</tt> method makes this a lot cleaner looking.  So really this is just some syntactic sugar, and I wish at least I could make it more of a general purpose <tt>if</tt> statement, but since I don&#8217;t need that sort of funcationality at this point, <acronym title="You're not going to need it.">YAGNI</acronym> tells me to leave that hurdle for another day.</p>
]]></content:encoded>
			<wfw:commentRss>http://kill-0.com/duplo/2008/05/01/javascript-conditionals-from-erb/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

