<?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>SmartLogic Solutions Blog &#187; interning</title>
	<atom:link href="http://blog.smartlogicsolutions.com/tag/interning/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.smartlogicsolutions.com</link>
	<description>News and updates from the people at SmartLogic Solutions</description>
	<lastBuildDate>Tue, 30 Nov 2010 21:39:14 +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>AASM + interning empty string error</title>
		<link>http://blog.smartlogicsolutions.com/2009/02/13/aasm-interning-empty-string-error/</link>
		<comments>http://blog.smartlogicsolutions.com/2009/02/13/aasm-interning-empty-string-error/#comments</comments>
		<pubDate>Fri, 13 Feb 2009 22:06:29 +0000</pubDate>
		<dc:creator>John Trupiano</dc:creator>
				<category><![CDATA[John Trupiano]]></category>
		<category><![CDATA[AASM]]></category>
		<category><![CDATA[error]]></category>
		<category><![CDATA[interning]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[rails2.1.2]]></category>
		<category><![CDATA[rubyist]]></category>
		<category><![CDATA[rubyist-aasm2.0.5]]></category>
		<category><![CDATA[string]]></category>

		<guid isPermaLink="false">http://blog.smartlogicsolutions.com/?p=507</guid>
		<description><![CDATA[Second time I&#8217;ve run into this in the past week, so I thought I&#8217;d share it with you guys. I fumbled for a short while with the extremely unhelpful error message &#8220;interning empty string error&#8221; after a re-deployment to my staging server. It seemed to be affecting all of my pages, and I couldn&#8217;t really [...]]]></description>
			<content:encoded><![CDATA[<p>Second time I&#8217;ve run into this in the past week, so I thought I&#8217;d share it with you guys.  I fumbled for a short while with the extremely unhelpful error message &#8220;interning empty string error&#8221; after a re-deployment to my staging server.  It seemed to be affecting all of my pages, and I couldn&#8217;t really load any page.</p>
<h3>The Problem</h3>
<div style="margin-top: 10px; padding: 4px; border: solid 1px black; background-color: #e0e0e0">This blog post is valid for rails 2.1.2 and rubyist-aasm 2.0.5.  It may apply to other version combinations, but I make no guarantees.</div>
<p>First, let&#8217;s dive into the error itself.  This error message occurs when you call to_sym on an empty string:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">john<span style="color:#006600; font-weight:bold;">-</span>mbp:trunk john$ irb
<span style="color:#006600; font-weight:bold;">&gt;&gt;</span> <span style="color:#996600;">&quot;&quot;</span>.<span style="color:#9900CC;">to_sym</span>
<span style="color:#CC00FF; font-weight:bold;">ArgumentError</span>: interning empty <span style="color:#CC0066; font-weight:bold;">string</span>
	from <span style="color:#006600; font-weight:bold;">&#40;</span>irb<span style="color:#006600; font-weight:bold;">&#41;</span>:<span style="color:#006666;">1</span>:<span style="color:#9966CC; font-weight:bold;">in</span> <span style="color:#996600;">`to_sym'
	from (irb):1</span></pre></div></div>

<p>Now that we know what&#8217;s up, let&#8217;s dig into my stack trace.  </p>
<div style="width: 500px;">
   /opt/ruby-enterprise-1.8.6-20090113/lib/ruby/gems/1.8/gems/rubyist-aasm-2.0.5/lib/persistence/active_record_persistence.rb:233:in `to_sym&#8217;<br />
   /opt/ruby-enterprise-1.8.6-20090113/lib/ruby/gems/1.8/gems/rubyist-aasm-2.0.5/lib/persistence/active_record_persistence.rb:233:in `aasm_read_state&#8217;<br />
   /opt/ruby-enterprise-1.8.6-20090113/lib/ruby/gems/1.8/gems/rubyist-aasm-2.0.5/lib/persistence/active_record_persistence.rb:135:in `aasm_current_state&#8217;<br />
   /opt/ruby-enterprise-1.8.6-20090113/lib/ruby/gems/1.8/gems/rubyist-aasm-2.0.5/lib/aasm.rb:50:in `disabled?&#8217;<br />
   /var/vhosts/discovered/releases/20090213213806/app/helpers/base_admin_helper.rb:4:in `disable_link&#8217;<br />
   /var/vhosts/discovered/releases/20090213213806/app/views/schools/index.rhtml:16:in `_run_erb_47app47views47schools47index46rhtml&#8217;<br />
   /var/vhosts/discovered/releases/20090213213806/app/views/schools/index.rhtml:12:in `each&#8217;<br />
   /var/vhosts/discovered/releases/20090213213806/app/views/schools/index.rhtml:12:in `_run_erb_47app47views47schools47index46rhtml&#8217;<br />
&#8230;<br />
&#8230;<br />
&#8230;
</div>
<p>The cause of this bug is the fact that my newest build added an aasm_state column to the School model, but my migration did not properly default schools to a particular state.  As such, when an instance of the model was asked for its state, the AASM codebase raised an error.  And this occurred on every page because I was rendering a link to a school in a common layout.</p>
<h3>The Solution</h3>
<p>After the fact, in SQL:</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">UPDATE</span> schools <span style="color: #993333; font-weight: bold;">SET</span> aasm_state <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'active'</span>;</pre></div></div>

<p>Or better yet, before the fact, in my migration:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">def</span> <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">up</span>
  add_column <span style="color:#ff3333; font-weight:bold;">:schools</span>, <span style="color:#ff3333; font-weight:bold;">:aasm_state</span>, :<span style="color:#CC0066; font-weight:bold;">string</span>
  School.<span style="color:#9900CC;">reset_column_information</span>
  School.<span style="color:#9900CC;">update_all</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;aasm_state&quot;</span>, <span style="color:#996600;">&quot;active&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<h3>The Lesson</h3>
<p>Don&#8217;t forget that there&#8217;s a difference between a migration for a yet-to-be-deployed application and a live running application.  Live apps require you to take into account that data already exists.</p>
<div id="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://blog.smartlogicsolutions.com/2008/06/03/error-in-will_paginate-gem-running-rails-210/" rel="bookmark" class="crp_title">Error in will_paginate gem running Rails 2.1.0</a></li><li><a href="http://blog.smartlogicsolutions.com/2008/09/04/ruby-patch-to-fix-broken-yamldump-for-multi-line-strings-stringto_yaml/" rel="bookmark" class="crp_title">Ruby: Patch to fix broken YAML.dump for multi-line strings (String#to_yaml)</a></li><li><a href="http://blog.smartlogicsolutions.com/2009/04/26/integrity-ci-on-passenger-222-with-ruby-enterprise-edition-on-ubuntu-804/" rel="bookmark" class="crp_title">Integrity CI on Passenger 2.2.2 with Ruby Enterprise Edition on Ubuntu 8.04</a></li><li><a href="http://blog.smartlogicsolutions.com/2010/05/13/directory-conventions-for-rack-middleware-rubygems/" rel="bookmark" class="crp_title">Directory Conventions for Rack Middleware RubyGems</a></li><li><a href="http://blog.smartlogicsolutions.com/2009/01/14/aptinstaller-032-released/" rel="bookmark" class="crp_title">Aptinstaller 0.3.2 Released</a></li><li>Powered by <a href="http://ajaydsouza.com/wordpress/plugins/contextual-related-posts/">Contextual Related Posts</a></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://blog.smartlogicsolutions.com/2009/02/13/aasm-interning-empty-string-error/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

