Nick Sieger: RailsConf: Amy Hoy - Overcoming Scaffolding Addictiondo what you lovetag:blog.nicksieger.com,2005:TypoTypo2007-08-31T16:41:58+00:00Nick Siegerurn:uuid:c75b0ef7-57f2-4856-9713-776cdef0bf232006-06-23T21:43:00+00:002007-08-31T16:41:58+00:00RailsConf: Amy Hoy - Overcoming Scaffolding Addiction<p>Scaffolding is not a swiss army knife, it’s more like a rusty spoon.
It’ll give you tetanus! Scaffolding leads to brain atrophy and
laziness. Leads to bad code, bad UI, etc. Instead, start from
scratch. <code>script/generate</code> is not inherently bad, it can write
necessary, tedious code for you.</p>
<pre><code>script/generate controller kitten create view put_to_sleep
</code></pre>
<p>This gives you:</p>
<div class="typocode"><pre><code class="typocode_ruby "><span class="keyword">class </span><span class="class">KittenController</span> <span class="punct"><</span> <span class="constant">ApplicationController</span>
<span class="keyword">def </span><span class="method">create</span>
<span class="keyword">end</span>
<span class="keyword">def </span><span class="method">view</span>
<span class="keyword">end</span>
<span class="keyword">def </span><span class="method">put_to_sleep</span>
<span class="keyword">end</span>
<span class="keyword">end</span></code></pre></div>
<p>Amy proceeds to break down a from-scratch, minimalist set of views, to
underscore the point that it’s not too hard to not use scaffolding.
I’d agree, it was so straightforward that unfortunately I’m going to
omit the details here. Rolling your own without scaffolding is
highly recommended.</p>
<p>Some of the items that you generally will experience in real world
apps but do not come in scaffolding are widgets for maintaining
relationships. Select lists based on a <code>belongs_to</code>, checkbox groups
for <code>has_many</code> are two examples.</p>
<p>Amy breaks these down as well and it turns out they’re pretty easy to
do. One snippet of code for updating checkboxes was succinct and
surprisingly readable, and made judicious use of the ruby array’s <code>-</code>
behavior to add newly checked and remove newly unchecked items
quickly.</p>
<p>Amy promised to post snippets and slides later on her blog, so go over
to <a href="http://www.slash7.com/">slash7</a> for more.</p>