<?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>Snow Giraffe Tech &#187; schemadumper</title>
	<atom:link href="http://www.snowgiraffe.com/tech/tag/schemadumper/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.snowgiraffe.com/tech</link>
	<description>rails, rubies, and sometimes dolphins</description>
	<lastBuildDate>Mon, 07 Jun 2010 14:36:05 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.5</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Enumeration Columns with Rails</title>
		<link>http://www.snowgiraffe.com/tech/311/enumeration-columns-with-rails/</link>
		<comments>http://www.snowgiraffe.com/tech/311/enumeration-columns-with-rails/#comments</comments>
		<pubDate>Thu, 19 Mar 2009 00:36:10 +0000</pubDate>
		<dc:creator>blythe</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[enum]]></category>
		<category><![CDATA[Enumeration]]></category>
		<category><![CDATA[Enumeration Column]]></category>
		<category><![CDATA[schemadumper]]></category>

		<guid isPermaLink="false">http://www.snowgiraffe.com/tech/?p=311</guid>
		<description><![CDATA[One of the many database features hated by Rails is enumerated columns. Even if you add them to your migration by dirtying your hands with SQL yourself, then the schemadumper interprets them as zero length strings as mentioned in Rob Sanheim&#8217;s blog. Funtime!
I however like enumerated columns because they save space and are pretty, and [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignright size-thumbnail wp-image-310" title="toolbox" src="http://www.snowgiraffe.com/tech/wp-content/uploads/2009/03/toolbox-150x150.gif" alt="toolbox" width="150" height="150" />One of the many database features hated by Rails is enumerated columns. Even if you add them to your migration by dirtying your hands with SQL yourself, then the <a href="http://caboo.se/doc/classes/ActiveRecord/SchemaDumper.html" target="_blank">schemadumper</a> interprets them as zero length strings as mentioned in <a href="http://robsanheim.com/2006/08/24/rails-schema-dumper-mysql-enums-bad-for-business/" target="_blank">Rob Sanheim&#8217;s blog.</a> Funtime!</p>
<p>I however like enumerated columns because they save space and are pretty, and so I wrote a short and sweet <a href="http://arperftoolkit.rubyforge.org/svn/trunk/migration_enum/init.rb" target="_blank">migration_enum plugin </a> to help me out. However, so be the fate of the web dev that someone else has already written a better one.</p>
<p>The solution is the <a href="http://enum-column.rubyforge.org/">Enumerated Columns</a> by William Sobel. He even added support for radio buttons in your views!</p>
<pre class="ruby"><span class="ident">t</span><span class="punct">.</span><span class="ident">column</span> <span class="symbol">:severity</span><span class="punct">,</span> <span class="symbol">:enum</span><span class="punct">,</span> <span class="symbol">:limit</span> <span class="punct">=&gt;</span> <span class="punct">[</span><span class="symbol">:low</span><span class="punct">,</span> <span class="symbol">:medium</span><span class="punct">,</span> <span class="symbol">:high</span><span class="punct">,</span> <span class="symbol">:critical</span><span class="punct">]</span></pre>
<p>The one thing I dislike is that my &#8220;legacy&#8221; system which has been using enumerated columns interprets them as strings all over the place in the rails code. Enumerated Columns plugins treats them as symbols and breaks me. To fix, I wrote a little <a href="http://snowgiraffe.com/downloads/rails/enum_patch.diff" target="_blank">patch</a>.</p>
<p><span id="more-311"></span></p>
<p>So to get it all:</p>
<pre>script/plugin install svn://rubyforge.org/var/svn/enum-column/plugins/enum-column
cd vendors/plugins/enum-columm
curl http://snowgiraffe.com/downloads/rails/enum_patch.diff &gt; enum_patch.diff
patch -p0 &lt; enum_patch.diff</pre>
<p>In environment.rb add:</p>
<pre class="ruby"><span class="constant">ActiveRecordEnumerations</span><span class="punct">::</span><span class="constant">Column</span><span class="punct">.</span><span class="ident">use_strings</span> <span class="punct">=</span> <span class="constant">true</span></pre>
]]></content:encoded>
			<wfw:commentRss>http://www.snowgiraffe.com/tech/311/enumeration-columns-with-rails/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
