<?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>LRBlog &#187; Ruby on Rails</title>
	<atom:link href="http://blog.lrdesign.com/category/development/rails/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.lrdesign.com</link>
	<description>Logical Reality Design: Web Design and Software Development</description>
	<lastBuildDate>Tue, 07 Jun 2011 21:43:04 +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>RSpec 2.0 and before/after hooks</title>
		<link>http://blog.lrdesign.com/2011/06/rspec-2-0-and-beforeafter-hooks/</link>
		<comments>http://blog.lrdesign.com/2011/06/rspec-2-0-and-beforeafter-hooks/#comments</comments>
		<pubDate>Tue, 07 Jun 2011 21:42:58 +0000</pubDate>
		<dc:creator>Judson</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://blog.lrdesign.com/?p=242</guid>
		<description><![CDATA[As of RSpec 2, the configuration interface for RSpec changed dramatically.  What used to look like: Spec::Runner.configure do &#124;config&#124; config.prepend_before&#40;:each, :type =&#38;gt; :controller&#41; do ... end end Now looks more like: RSpec::configure do &#124;config&#124; config.before&#40;:each, :line =&#38;gt; 153&#41; do end end One significant and interesting change is the way that before hooks are processed.  Specifically, [...]]]></description>
			<content:encoded><![CDATA[<p>As of RSpec 2, the configuration interface for RSpec changed dramatically.  What used to look like:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#6666ff; font-weight:bold;">Spec::Runner</span>.<span style="color:#9900CC;">configure</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>config<span style="color:#006600; font-weight:bold;">|</span>
config.<span style="color:#9900CC;">prepend_before</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:each</span>, <span style="color:#ff3333; font-weight:bold;">:type</span> =<span style="color:#006600; font-weight:bold;">&amp;</span>gt; <span style="color:#ff3333; font-weight:bold;">:controller</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">do</span>
...
<span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>Now looks more like:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">RSpec::configure <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>config<span style="color:#006600; font-weight:bold;">|</span>
  config.<span style="color:#9900CC;">before</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:each</span>, <span style="color:#ff3333; font-weight:bold;">:line</span> =<span style="color:#006600; font-weight:bold;">&amp;</span>gt; <span style="color:#006666;">153</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">do</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>One significant and interesting change is the way that before hooks are processed.  Specifically, the #before, #after, and #around methods are now part of the Hooks module, which is included in both ExampleGroup and in Configuration, so you call configure.before in exactly the same way as you do within a describe block.  Normally, you pass :each or :all, which sets the scope under which the hook will be called, but Hooks inspects the arguments for filtering metadata regardless of where you call it - I don't know that you'd <em>want</em> filter within an ExampleGroup, but you could...</p>
<p>Unfortunately, as cool as the metadata filtering capabilities are they aren't, as far as I can tell, very well documented.  The process of extracting the metadata lives in it's own <code>:nodoc:</code> limbo, and the attachment of metadata to a particular example is scattered throughout the RSpec code.  This, then, is an attempt to pick that apart.</p>
<h2>Extracting Filters</h2>
<p>When you call Hooks#before, for example (#after and #around work fundamentally the same way), the args are examined and two things are extracted:</p>
<p>A scope, which is the :each, :all, or :suite specification.</p>
<p>A metadata filter hash.  Normally, you call <code>#before(:each, {:hash =&gt; [:of, :metadata]})</code>, but you can instead do something like <code>before(:all, :symbol)</code> which will result in a metadata filter like <code>{:symbol =&gt; true}</code></p>
<p>Again, probably if you need to add metadata inside of a describe block, you are Doing Something Wrong, but maybe there's a good reason.  The extreme (excessive?) flexibility of RSpec metadata and filtering does open up a lot of interesting possibilities.</p>
<h2>Filter Matching</h2>
<p>The metadata filter is used to decide if the hook should be run for a particular example block that it might apply to.  As such, it's a remarkably powerful filtering system, although there's a lot of assumptions about it's format that you need to bear in mind.</p>
<p>The actual mechanics of the metadata filtering happen in <code>RSpec::Core::Metadata#apply?</code> and <code>#apply_condition</code> - there's a long chain of delegation and extra-meta-programming that leads there.</p>
<p>The upshot is that your metadata filter will be compared to the metadata on the example key/value pair by pair, like this:</p>
<ul>
<li>A regular expression in the filter will match against the appropriate value for the example.</li>
<li>If you pass :line_number =&gt; 17, Rspec will check to see if the example includes line 17, much like running rspec filename_spec.rb:17</li>
<li>Any other Fixnum will be compared with == to the value in the metadata</li>
<li>Anything else gets compared with == to the value in the metadata, after both values have been converted to a string.</li>
<li>A proc like <code>{|value| ... }</code> will get the value of the key, and can return true for a match.</li>
</ul>
<p>Filters can nest Hashes, which will be compared to nested Hashes in the metadata.  In other words, if you want to be able to match for metadata like</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#006600; font-weight:bold;">&#123;</span>...,  :example_group =<span style="color:#006600; font-weight:bold;">&amp;</span>gt; <span style="color:#006600; font-weight:bold;">&#123;</span>..., <span style="color:#ff3333; font-weight:bold;">:full_description</span> =<span style="color:#006600; font-weight:bold;">&amp;</span>gt; <span style="color:#996600;">&quot;A very long winded example of the group&quot;</span>, ...<span style="color:#006600; font-weight:bold;">&#125;</span>, ...<span style="color:#006600; font-weight:bold;">&#125;</span></pre></div></div>

<p>You can do something like:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">before<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:each</span>, <span style="color:#006600; font-weight:bold;">&#123;</span>:example_group =<span style="color:#006600; font-weight:bold;">&amp;</span>gt;<span style="color:#006600; font-weight:bold;">&#123;</span>:full_description =<span style="color:#006600; font-weight:bold;">&amp;</span>gt; <span style="color:#006600; font-weight:bold;">/</span>long winded<span style="color:#006600; font-weight:bold;">/</span><span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span></pre></div></div>

<div>RSpec attaches some metadata to examples and groups, but you can also explicitly add metadata to groups and examples as they're defined.  One useful example of that is</div>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">it <span style="color:#996600;">&quot;should do something useful, someday&quot;</span>, <span style="color:#ff3333; font-weight:bold;">:pending</span> =<span style="color:#006600; font-weight:bold;">&amp;</span>gt; <span style="color:#996600;">&quot;Not this day, though&quot;</span></pre></div></div>

<p>Which is much faster than using the pending method call inside the block, and can be applied to a describe block to make the whole thing pending - especially handy when you have a before block inside that is causing problems.</p>
<p>In the same token, the example given in RSpec 2 documentation and announcement posts has been doing something like:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">it <span style="color:#996600;">&quot;should not be taking this looooong&quot;</span>, <span style="color:#ff3333; font-weight:bold;">:slow</span> =<span style="color:#006600; font-weight:bold;">&amp;</span>gt; <span style="color:#0000FF; font-weight:bold;">true</span></pre></div></div>

<p>Since metadata can also be used to filter examples, you could use this to pull out the examples that take forever from your all-the-time specs, and run them only before a push, for instance.</p>
<h2>What Metadata Does RSpec Give Us?</h2>
<p>Probably the best way to figure that out is this very pragmatic approach.</p>
<h3>A Useful Trick</h3>
<p>Very useful for experimenting with metadata is that the proc form of the metadata has a special case: if the proc takes two arguments, the whole metadata hash will get passed into the proc, so you can inspect it at leisure.  The snippet looks like:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'pp'</span>
before<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:each</span>, <span style="color:#ff3333; font-weight:bold;">:bogus</span> =<span style="color:#006600; font-weight:bold;">&amp;</span>gt; <span style="color:#CC0066; font-weight:bold;">proc</span><span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">|</span>val, all<span style="color:#006600; font-weight:bold;">|</span> pp all<span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">&#125;</span></pre></div></div>

<div>From a Rails controller spec:</div>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#006600; font-weight:bold;">&#123;</span>
<span style="color:#ff3333; font-weight:bold;">:execution_result</span>=<span style="color:#006600; font-weight:bold;">&amp;</span>gt;<span style="color:#006600; font-weight:bold;">&#123;</span>:started_at=<span style="color:#006600; font-weight:bold;">&amp;</span>gt;Tue Jun 07 <span style="color:#006666;">14</span>:<span style="color:#006666;">13</span>:<span style="color:#006666;">46</span> <span style="color:#006600; font-weight:bold;">-</span>0700 <span style="color:#006666;">2011</span><span style="color:#006600; font-weight:bold;">&#125;</span>,
<span style="color:#ff3333; font-weight:bold;">:type</span>=<span style="color:#006600; font-weight:bold;">&amp;</span>gt;:controller,
<span style="color:#ff3333; font-weight:bold;">:full_description</span>=<span style="color:#006600; font-weight:bold;">&amp;</span>gt;<span style="color:#996600;">&quot;UserSessionsController should be authorized&quot;</span>,
<span style="color:#ff3333; font-weight:bold;">:description</span>=<span style="color:#006600; font-weight:bold;">&amp;</span>gt;<span style="color:#996600;">&quot;should be authorized&quot;</span>,
<span style="color:#ff3333; font-weight:bold;">:example_group</span>=<span style="color:#006600; font-weight:bold;">&amp;</span>gt;
  <span style="color:#006600; font-weight:bold;">&#123;</span>
  <span style="color:#ff3333; font-weight:bold;">:full_description</span>=<span style="color:#006600; font-weight:bold;">&amp;</span>gt;<span style="color:#996600;">&quot;UserSessionsController&quot;</span>,
  <span style="color:#ff3333; font-weight:bold;">:file_path</span>=<span style="color:#006600; font-weight:bold;">&amp;</span>gt; <span style="color:#996600;">&quot;spec/controllers/user_sessions_controller_spec.rb&quot;</span>,
  <span style="color:#ff3333; font-weight:bold;">:describes</span>=<span style="color:#006600; font-weight:bold;">&amp;</span>gt;UserSessionsController,
  <span style="color:#ff3333; font-weight:bold;">:description</span>=<span style="color:#006600; font-weight:bold;">&amp;</span>gt;<span style="color:#996600;">&quot;UserSessionsController&quot;</span>,
  <span style="color:#ff3333; font-weight:bold;">:block</span>=<span style="color:#006600; font-weight:bold;">&amp;</span>gt; <span style="color:#008000; font-style:italic;">#</span>
,
  <span style="color:#ff3333; font-weight:bold;">:line_number</span>=<span style="color:#006600; font-weight:bold;">&amp;</span>gt;<span style="color:#006666;">3</span>,
  :<span style="color:#CC0066; font-weight:bold;">caller</span>=<span style="color:#006600; font-weight:bold;">&amp;</span>gt; <span style="color:#006600; font-weight:bold;">&#91;</span> ... <span style="color:#9900CC;">the</span> whole backtrace of the group ... <span style="color:#006600; font-weight:bold;">&#93;</span>
  <span style="color:#006600; font-weight:bold;">&#125;</span>,
:<span style="color:#CC0066; font-weight:bold;">caller</span>=<span style="color:#006600; font-weight:bold;">&amp;</span>gt; <span style="color:#006600; font-weight:bold;">&#91;</span> ... <span style="color:#9900CC;">the</span> backtrace of the example ...<span style="color:#006600; font-weight:bold;">&#93;</span>
<span style="color:#006600; font-weight:bold;">&#125;</span></pre></div></div>

<p>One of the cool-but-problematic things about metadata in RSpec is that it get's added and updated all over the codebase, and constantly over the lifecycle of an example run and extensions (like Rspec-Rails) add their own fields and values, so it's very hard to have formal documentation for what you can match.  Also, somewhat troubling, is that none of these fields are an explicit part of the RSpec API, and so might change with very little notice.  It seems like the best way to manage working with the metadata is with the above pragmatic approach.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.lrdesign.com/2011/06/rspec-2-0-and-beforeafter-hooks/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Extending form_for in Rails 3 with your own methods</title>
		<link>http://blog.lrdesign.com/2011/04/extending-form_for-in-rails-3-with-your-own-methods/</link>
		<comments>http://blog.lrdesign.com/2011/04/extending-form_for-in-rails-3-with-your-own-methods/#comments</comments>
		<pubDate>Mon, 25 Apr 2011 19:58:12 +0000</pubDate>
		<dc:creator>Evan</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[adding methods]]></category>
		<category><![CDATA[extending]]></category>
		<category><![CDATA[FormBuilder]]></category>
		<category><![CDATA[form_for]]></category>
		<category><![CDATA[Gems]]></category>
		<category><![CDATA[Rails 3]]></category>

		<guid isPermaLink="false">http://blog.lrdesign.com/?p=272</guid>
		<description><![CDATA[The code that handles <code>form_for</code> in Rails 3 is rather dense and incomprehensible and takes a while to pore through.   Here's the short version to understanding it so you can add your own methods to <code>FormBuilder</code> properly.   Since we dug through it, hopefully this will save others some time. ]]></description>
			<content:encoded><![CDATA[<p>At LRDesign, we have a bunch of internal tools to make laying out Rails views more consistent.  I recently upgraded and improved some of ours for Rails 3, and published them as a gem.  (The published / open source ones are available at <a href="https://github.com/LRDesign/lrd_view_tools">https://github.com/LRDesign/lrd_view_tools</a>, if you're interested).  One of the handy techniques we figured out (poring through the Rails code) is how to correctly add a method to <code>FormBuilder</code> so that you can properly use it inside a <code>form_for</code>  block.</p>
<h2>An example method added to forms:</h2>
<p>Since I nearly always want<code> &lt;input&gt;</code> and <code>&lt;label&gt;</code> tags at the same time, I created a <code>labeled_input</code> method that lets me say this (in HAML):</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">= form_for<span style="color:#006600; font-weight:bold;">&#40;</span>@book<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>f<span style="color:#006600; font-weight:bold;">|</span>
    = f.<span style="color:#9900CC;">labeled_input</span> <span style="color:#ff3333; font-weight:bold;">:title</span>
    = f.<span style="color:#9900CC;">labeled_input</span> <span style="color:#ff3333; font-weight:bold;">:author</span>
    = f.<span style="color:#9900CC;">labeled_input</span> <span style="color:#ff3333; font-weight:bold;">:price</span></pre></div></div>

<p>to get:</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;form action=&quot;/books/new&quot;&gt;
  &lt;div class=&quot;labeled_input&quot;&gt;
    &lt;label for=&quot;book_title&quot;&gt;Title:&lt;/label&gt;&lt;input id=&quot;book_title&quot; name=&quot;book[title]&quot; type=&quot;text&quot; /&gt;
  &lt;/div&gt;
  &lt;div class=&quot;labeled_input&quot;&gt;
    &lt;label for=&quot;book_author&quot;&gt;Author:&lt;/label&gt;&lt;input id=&quot;book_author&quot; name=&quot;book[author]&quot; type=&quot;text&quot; /&gt;
  &lt;/div&gt;
  &lt;div class=&quot;labeled_input&quot;&gt;
    &lt;label for=&quot;book_price&quot;&gt;Price:&lt;/label&gt;
    &lt;input id=&quot;book_price&quot; name=&quot;book[price]&quot; type=&quot;text&quot; /&gt;
  &lt;/div&gt;
&lt;/form&gt;</pre></div></div>

<p>Combined with some default CSS code in our application template that aligns the <code>&lt;label&gt;</code>s and <code>&lt;input&gt;</code>s in columns, this saves us a couple of hours setting up clean-looking forms on every new project, while significantly shortening and prettifying our view templates.   (Markup Haiku, just like HAML intended.)</p>
<h2>Implementing the extension in Rails 3</h2>
<p>The code that handles <code>form_for</code> in Rails 3 is rather dense and incomprehensible and takes a while to pore through.   Here's the short version to understanding it so you can add your own methods to <code>FormBuilder</code> properly.   Since we dug through it, hopefully this will save others some time.    The only Rails file you care about for this purpose is actionpack-3.0.x/lib/action_view/helpers/form_helper.rb.</p>
<ul>
<li><code>module ActionView::Helpers::FormHelper</code> defines a bunch of helpers, like <code>label</code>, <code>text_field</code>, etc. that define helpers you use <em>outside of a <code>form_for</code></em>.  For example, <code>text_field(@user, :title)</code> calls this version of the helper.</li>
<li><code>class ActionView::Helpers::FormBuilder</code> is what's used to define the helpers you run <em>inside</em> a <em>form_for</em>.   It works automatically via metaprogramming ... when loaded, it finds each helper in <code>FormHelper</code> (except for a few) and defines a similarly named method in <code>FormBuilder</code>.    <code>form_for(@user) { |f| f.text_field(:title)</code> calls this version of the helper, which basically just calls the FormHelper version but passes the FormBuilder's @object_name as an additional first argument.   In version 3.0.7, this metaprogramming happens on lines 1131-1141 of form_helper.rb.</li>
<li>As a result, if you were to write a new helper in <code>ActionView::Helpers::FormHelper</code> that uses the same argument structure as the pre-built ones, you'd automatically get both kinds of helper.    However, if you're writing your own plugin or gem and injecting new helpers, this won't happen because by the time you inject your method FormBuilder will have already done its metaprogramming (it happens when the file is loaded).</li>
<li>The solution to this is that your gem needs to do the second half - defining the <code>FormBuilder</code> version of the helper - itself.  I'll put an example below.</li>
<li>Most of the helper methods work by instantiating InstanceTag, a local one-size-fits-all class to emit a form tag, and then calling the appropriate method for the kind of tag that's wanted, like <code>to_text_field_tag</code>.  It's very confusing why the Rails team decided to do one class for InstanceTag and a bunch of different methods, rather than make subclasses of InstanceTag for each kind of tag they want; an odd OOP decision, but that's what we've got.</li>
<li>InstanceTag itself has only one line:  it includes InstanceTagMethods, a model that defines all the methods for the class, and which isn't used elsewhere.</li>
</ul>
<p>So to implement a <code>FormBuilder</code> method yourself that you can use inside a form_for, the best way is to inject your method inside <code>FormHelper</code>, and then call that from a method you inject into <code>FormBuilder</code>.   This gives you both versions of the method, in the same structure that Rails defines them.   You could do this either in a helper file directly in your application, or in a gem (like we have) so you can reuse your form helpers in more than one projects.   </p>
<h2>An example implementation.</h2>
<p>Here's a simplified construction of the <code>labeled_input</code> method we use at LRD.  This one just emits a label and a text field and wraps them in a &lt;div&gt;.</p>
<h3>Start by defining the helper:</h3>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">module</span> LRD
  <span style="color:#9966CC; font-weight:bold;">module</span> FormHelper
    <span style="color:#9966CC; font-weight:bold;">def</span> labeled_input<span style="color:#006600; font-weight:bold;">&#40;</span>object_name, method, options = <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
      input = text_field<span style="color:#006600; font-weight:bold;">&#40;</span>object_name, method, options<span style="color:#006600; font-weight:bold;">&#41;</span>
      label = label<span style="color:#006600; font-weight:bold;">&#40;</span>object_name, method, options<span style="color:#006600; font-weight:bold;">&#41;</span>
      content_tag<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:div</span>, <span style="color:#006600; font-weight:bold;">&#40;</span>label<span style="color:#006600; font-weight:bold;">+</span>input<span style="color:#006600; font-weight:bold;">&#41;</span>, <span style="color:#006600; font-weight:bold;">&#123;</span> :<span style="color:#9966CC; font-weight:bold;">class</span> =<span style="color:#006600; font-weight:bold;">&amp;</span>gt; <span style="color:#996600;">'labeled_input'</span> <span style="color:#006600; font-weight:bold;">&#125;</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#6666ff; font-weight:bold;">ActionView::Helpers::FormHelper</span>.<span style="color:#9900CC;">send</span><span style="color:#006600; font-weight:bold;">&#40;</span>:<span style="color:#9966CC; font-weight:bold;">include</span>, <span style="color:#6666ff; font-weight:bold;">LRD::FormHelper</span><span style="color:#006600; font-weight:bold;">&#41;</span></pre></div></div>

<p>This will successfully define <code>labeled_input</code> that you can use outside of a form_for.   </p>
<h3>Now add the FormBuilder version:</h3>
<p>To get it working inside of a form_for, you need to add a similar method to <code>ActionView::Helpers::FormBuilder</code>.   As mentioned above, Rails does this automatically for its own <code>FormHelper</code> methods using a metaprogramming approach.  But since that has already happened by the time your code can inject into <code>FormHelper</code>, you have to do it yourself.   The solution we used is to make our own <code>FormBuilder</code> module that manually defines the <code>labeled_input</code> method in the same format that <code>FormBuilder</code> would have done, and then auto-include that into <code>FormBuilder</code> when our own <code>FormHelper</code> module gets included.  Add this stuff to the above code block:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#008000; font-style:italic;"># Inside LRD::FormHelper, add this method:</span>
<span style="color:#9966CC; font-weight:bold;">def</span> <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">included</span><span style="color:#006600; font-weight:bold;">&#40;</span>arg<span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#6666ff; font-weight:bold;">ActionView::Helpers::FormBuilder</span>.<span style="color:#9900CC;">send</span><span style="color:#006600; font-weight:bold;">&#40;</span>:<span style="color:#9966CC; font-weight:bold;">include</span>, <span style="color:#6666ff; font-weight:bold;">LRD::FormBuilder</span><span style="color:#006600; font-weight:bold;">&#41;</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">module</span> <span style="color:#6666ff; font-weight:bold;">LRD::FormBuilder</span>
  <span style="color:#008000; font-style:italic;"># ActionPack's metaprogramming would have done this for us, if FormHelper#labeled_input </span>
  <span style="color:#008000; font-style:italic;"># had been defined  at load.   Instead we define it ourselves here.</span>
  <span style="color:#9966CC; font-weight:bold;">def</span> labeled_input<span style="color:#006600; font-weight:bold;">&#40;</span>method, options = <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#0066ff; font-weight:bold;">@template</span>.<span style="color:#9900CC;">labeled_input</span><span style="color:#006600; font-weight:bold;">&#40;</span>@object_name, method, objectify_options<span style="color:#006600; font-weight:bold;">&#40;</span>options<span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>In practice, our <code>labeled_input</code> method is much more complex; it handles other input types, can add instructional comments/notes to the field, and can accept a block if you want to put something other than an <code>&lt;input&gt;</code> where the text field normally goes.   This guide should get you started to writing your own <code>form_for</code> methods quickly, but if you want to see how to do more complex things, check out <a href="https://github.com/LRDesign/lrd_view_tools/blob/master/lib/app/helpers/lrd_form_helper.rb">the full version</a>.</p>
<h2>Adding more input types or other tags.</h2>
<p>If you wanted to add an entire different tag or input type (as opposed to combining different ones, the way <code>labeled_input</code> does), you would probably start by building a module that you inserted into <code>InstanceTag</code> or <code>InstanceTagMethods</code>.  It should define a method like <code>MyInstanceTagModule#to_some_funky_tag()</code> in parallel <code>with to_input_field_tag()</code>.</p>
<h2>Testing it with rSpec 2</h2>
<p>Another challenge we faced was writing specs for <code>labeled_input's</code> behavior.  It's a bit of a trick because we needed to instantiate <code>ActionView</code> and render some templates to check the output, but rspec-rails is written with the assumption that you will be loading an entire rails project and all the rails gems. If you want to spec just a view helper, you need to load a bunch of rspec-rails's files one by one, and then manually include <code>RSpec::Rails::ViewExampleGroup</code> into RSpec's configuration.   We may write a separate post on this process in the future, but in the meantime, take a look at <a href="https://github.com/LRDesign/lrd_view_tools/blob/master/spec/spec_helper.rb">lrd_view_tools' spec_helper file</a> and <a href="https://github.com/LRDesign/lrd_view_tools/blob/master/spec/labelled_input_spec.rb">example spec for labeled_input</a> to get the sense of it.</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.lrdesign.com/2011/04/extending-form_for-in-rails-3-with-your-own-methods/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>On the road to faster specs</title>
		<link>http://blog.lrdesign.com/2011/01/on-the-road-to-faster-specs/</link>
		<comments>http://blog.lrdesign.com/2011/01/on-the-road-to-faster-specs/#comments</comments>
		<pubDate>Fri, 21 Jan 2011 23:39:41 +0000</pubDate>
		<dc:creator>Evan</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://blog.lrdesign.com/?p=234</guid>
		<description><![CDATA[ Just drop this blob of code at the bottom of your spec_helper.rb - I saw a 43% speed increase in one project's spec suite. ]]></description>
			<content:encoded><![CDATA[<p>Running large spec or test suites can be a bane of Rails developers.   I've certainly stopped using autotest since half of our projects started exceeding 5 minutes of spec runtime.   After seeing (three times!) presentations by <a href="http://twitter.com/#!/tmm1">Aman Gupta</a>, I had spent some time with perftools trying to figure out what the heck was making my specs take so long.   It's not just that more specs take more time to run: if you clock individual specs you will see identical examples run slower in a larger project.  I'd seen that rspec runs can spend upwards of 60% of their time in the garbage collector, but not pursued it further than that.</p>
<p>A couple days ago, Jamis at the 37Signals blog took this idea further, dug into ActiveSupport::TestCase, and generated <a href="http://37signals.com/svn/posts/2742-the-road-to-faster-tests">this wonderful blog post</a> that explains his findings and how to get a 40% or more speedup in Test::Unit.  His solution involves  reducing the frequency of garbage collection and forcing ActiveSupport::TestCase to destroy instance variables it doesn't need anymore).</p>
<p>It's great, but if you do exactly what he says it won't quite work in RSpec - and RSpec users should get to enjoy this new development, too!  While RSpec makes use of ActiveSupport::TestCase, it has a different set of internal instance variables, and Jamis' code will end up erasing the variables that store your actual examples.   If you drop in Jamis' code to spec_helper.rb you'll see this error:</p>
<pre>
vendor/rails/activesupport/lib/active_support/whiny_nil.rb:52:in `method_missing':
 undefined method `description' for nil:NilClass (NoMethodError)
</pre>
<p>All that's needed to make RSpec happy is a little tweak to Jamis' code that protects a different set of instance variables from being unset.   Just drop this blob of code at the bottom of your spec_helper.rb - I saw a 43% speed increase in one project's spec suite.  (Note that if you are still using fixtures, you might need to add @loaded_fixtures and/or @fixture_cache to @@reserved_ivars;  at LRD we long since abandoned fixtures in favor of factories, so I haven't tested this on spec suites with fixtures).</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">class</span> <span style="color:#6666ff; font-weight:bold;">ActiveSupport::TestCase</span>
  setup <span style="color:#ff3333; font-weight:bold;">:begin_gc_deferment</span>
  teardown <span style="color:#ff3333; font-weight:bold;">:reconsider_gc_deferment</span>
  teardown <span style="color:#ff3333; font-weight:bold;">:scrub_instance_variables</span>
&nbsp;
  @@reserved_ivars = <span style="color:#006600; font-weight:bold;">%</span>w<span style="color:#006600; font-weight:bold;">&#40;</span>@_implementation <span style="color:#0066ff; font-weight:bold;">@_result</span> <span style="color:#0066ff; font-weight:bold;">@_proxy</span>  <span style="color:#0066ff; font-weight:bold;">@_assigns_hash_proxy</span> <span style="color:#0066ff; font-weight:bold;">@_backtrace</span><span style="color:#006600; font-weight:bold;">&#41;</span>
  DEFERRED_GC_THRESHOLD = <span style="color:#006600; font-weight:bold;">&#40;</span>ENV<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'DEFER_GC'</span><span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#006600; font-weight:bold;">||</span> <span style="color:#006666;">1.0</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">to_f</span>
&nbsp;
  @@last_gc_run = <span style="color:#CC00FF; font-weight:bold;">Time</span>.<span style="color:#9900CC;">now</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> begin_gc_deferment
    <span style="color:#CC00FF; font-weight:bold;">GC</span>.<span style="color:#9900CC;">disable</span> <span style="color:#9966CC; font-weight:bold;">if</span> DEFERRED_GC_THRESHOLD <span style="color:#006600; font-weight:bold;">&gt;</span> <span style="color:#006666;">0</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> reconsider_gc_deferment
    <span style="color:#9966CC; font-weight:bold;">if</span> DEFERRED_GC_THRESHOLD <span style="color:#006600; font-weight:bold;">&gt;</span> <span style="color:#006666;">0</span> <span style="color:#006600; font-weight:bold;">&amp;&amp;</span> <span style="color:#CC00FF; font-weight:bold;">Time</span>.<span style="color:#9900CC;">now</span> <span style="color:#006600; font-weight:bold;">-</span> @@last_gc_run <span style="color:#006600; font-weight:bold;">&gt;</span>= DEFERRED_GC_THRESHOLD
      <span style="color:#CC00FF; font-weight:bold;">GC</span>.<span style="color:#9900CC;">enable</span>
      <span style="color:#CC00FF; font-weight:bold;">GC</span>.<span style="color:#9900CC;">start</span>
      <span style="color:#CC00FF; font-weight:bold;">GC</span>.<span style="color:#9900CC;">disable</span>
&nbsp;
      @@last_gc_run = <span style="color:#CC00FF; font-weight:bold;">Time</span>.<span style="color:#9900CC;">now</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> scrub_instance_variables
    <span style="color:#006600; font-weight:bold;">&#40;</span>instance_variables <span style="color:#006600; font-weight:bold;">-</span> @@reserved_ivars<span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>ivar<span style="color:#006600; font-weight:bold;">|</span>
      instance_variable_set<span style="color:#006600; font-weight:bold;">&#40;</span>ivar, <span style="color:#0000FF; font-weight:bold;">nil</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>(Most of this code is Jamis', and I'm not taking credit for his fantastic work.)</p>
<p>RSpec already does a much better job of handling instance variables than Test::Unit, so the scrubbing didn't produce a big speedup for me (only about 5%).   But the GC deferment did indeed give me a 43% speed improvement in the spec suite for my biggest project; run time dropped from 7m38s to 4m23s ... what a difference!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.lrdesign.com/2011/01/on-the-road-to-faster-specs/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Convection: self-hosted secure file exchange in Rails</title>
		<link>http://blog.lrdesign.com/2010/06/convection-self-hosted-secure-file-exchange-in-rails/</link>
		<comments>http://blog.lrdesign.com/2010/06/convection-self-hosted-secure-file-exchange-in-rails/#comments</comments>
		<pubDate>Wed, 09 Jun 2010 02:54:03 +0000</pubDate>
		<dc:creator>Evan</dc:creator>
				<category><![CDATA[File Exchange]]></category>
		<category><![CDATA[Projects]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[client management]]></category>
		<category><![CDATA[file upload]]></category>
		<category><![CDATA[security]]></category>

		<guid isPermaLink="false">http://blog.lrdesign.com/?p=160</guid>
		<description><![CDATA[Need to swap files with clients or collaborators, but don't want to (or can't) trust those files to Amazon or sendbigfiles.com?  Want fine-grained control over which users can see which files?   Try Convection.]]></description>
			<content:encoded><![CDATA[<p><a href="http://blog.lrdesign.com/wp-content/uploads/2010/06/convection.png"><img src="http://blog.lrdesign.com/wp-content/uploads/2010/06/convection.png" alt="" title="convection" width="100" height="100" class="alignleft size-full wp-image-166" style="margin-right: 1em;" /></a>Introducing <a href="http://github.com/LRDesign/Convection">Convection</a>, an open-source (MIT License) project of Logical Reality Design.    Need to swap files with clients or collaborators, but don't want to (or can't) trust those files to Amazon or sendbigfiles.com?  Want fine-grained control over which users can see which files?   Try Convection.</p>
<p>Lots of file exchange services exist, for example SendBigFiles.com etc.  However, all of these services are hosted on someone else's hardware, and most of them share files by transferring URLs -- usually via email -- without good access control or authorization schemes. </p>
<p>We built Convection because a client needed to transfer files with other companies, but they needed to host the system themselves because the contracts they hold with their own clients require them not to store data on services that they don't control.   The specifications Convection was built around were:</p>
<ol>
<li>Hosted on our own server.</li>
<li>Downloads require a login, and files cannot be shared by email.</li>
<li>Users must log in to download files or see available files.</li>
<li>User accounts can be grouped, groups can be managed.</li>
<li>Files can be shared with an entire group.</li>
<li>Files uploaded by users default to minimal permission - visible only to the uploader and to admins.</li>
<li>All communications over SSL. (we made this optional)</li>
</ol>
<h2>Installing and hosting Convection</h2>
<p>To run Convection, you will need a webserver capable of running a Ruby on Rails application, and a database.   Setting such a thing up is beyond the scope of this post.   If you have a Dreamhost account, you can set up a Rails-capable domain with a couple of clicks in their web panel.  In addition to the server, you will need to set up a database (we have only tested MySQL, but Convection should work with any SQL database for which Rails/ActiveRecord has a supported adapter, including PostgreSQL and Oracle), and initialize the database with these two commands:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">  <span style="color: #000000; font-weight: bold;">&gt;</span> rake db:migrate <span style="color: #007800;">RAILS_ENV</span>=production
  <span style="color: #000000; font-weight: bold;">&gt;</span> rake db:seed <span style="color: #007800;">RAILS_ENV</span>=production</pre></div></div>

<p>This will generate the tables necessary for Convection to run, and create a pair of initial demo users "admin" and "user", both with password "foobar".   </p>
<p>If you are setting up a server yourself, there are plenty of guides to deploying Rails on the web.   Much of our own <a href="http://blog.lrdesign.com/2010/02/howto-setting-up-cruisecontrol-rb-on-slicehost/">guide to deploying CruiseControl.rb</a> can be used to set up any Rails application on Slicehost or any other Ubuntu Linux hosting provider.  </p>
<p>Let me know if you're trying to deploy Convection and having trouble: if we know people are using it we may put effort into making it easier to deploy and install, and write a more thorough guide.</p>
<p>A few other links that may help you with deploying a Rails application, depending on your environment:</p>
<ol>
<li><a href="http://wdvl.com/Authoring/ror/Passenger/saurabh_bhatia04142010.html">Using Phusion Passenger to Deploy a Rails Application on Apache</a></li>
<li><a href="http://pragprog.com/titles/fr_deploy/deploying-rails-applications">Deploying Rails Applications (book)</a></li>
</ol>
<p>If you Google around you may find plenty of other links relevant to your particular environment.</p>
<h2>Configuring Convection</h2>
<p>If you log into your running Convection application as an administrator (initial user "admin", password "foobar"), an Admin Tools utility will appear in the right hand column.   From here, you can access tools for creating users, and groups, and the general site configuration.</p>
<p>In general site config, you can set your site name and logo, set whether or not the site requires SSL access (Note: your server must already support SSL!) outgoing email and email notification preferences, add Google analytics, and an assortment of other site configuration operations that are mostly self-explanatory. </p>
<h2>Upload progress bar: experimental feature.</h2>
<p>If your site hosts large uploads that take a while to transfer, you can try our experimental tools to provide an upload progress bar to the user.   This tool will only work if your site is served by Apache, and requires installing and configuring an optional module for Apache.</p>
<p>To enable this tool, follow the instructions in the README file and associated links, and turn on the progress bar setting in site preferences.</p>
<h2>Helping us improve Convection</h2>
<p>Convection is currently in version 1.1.4 and has been in production in two places (that we know of) for about five months as of June 8, 2010.   </p>
<p>Please let us know if you are using Convection and enjoy it (or don't).   Feel free to request features or alterations, but Convection is open source, so also please consider contributing if you have ideas!  </p>
]]></content:encoded>
			<wfw:commentRss>http://blog.lrdesign.com/2010/06/convection-self-hosted-secure-file-exchange-in-rails/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>Transactional Testing for Multiple Databases in ActiveRecord</title>
		<link>http://blog.lrdesign.com/2010/03/transactional-testing-for-multiple-databases-in-activerecord/</link>
		<comments>http://blog.lrdesign.com/2010/03/transactional-testing-for-multiple-databases-in-activerecord/#comments</comments>
		<pubDate>Fri, 19 Mar 2010 06:36:27 +0000</pubDate>
		<dc:creator>Judson</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://blog.lrdesign.com/?p=130</guid>
		<description><![CDATA[We've been working on an app that needs to stand astride two databases - one local DB for the app itself, and another with restrictive policies about modifications that is nonetheless authoritative on many subjects. There's a fair amount of tricky interaction between the two, and testing has been a delightful challenge. We're using the [...]]]></description>
			<content:encoded><![CDATA[<p>We've been working on an app that needs to stand astride two databases - one local DB for the app itself, and another with restrictive policies about modifications that is nonetheless authoritative on many subjects.  There's a fair amount of tricky interaction between the two, and testing has been a delightful challenge.</p>
<p>We're using the use_db plugin, and all it takes to make testing transactions happen around multiple DBs is:</p>
<p><code>In: spec/spec_helper.rb</code></p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'override_test_callbacks'</span></pre></div></div>

<p>My concern comes from the fact that this is a direct and unfiltered monkeypatch on ActiveRecord::TestFixtures.  So it relies on <code>use_transactional_fixtures</code> (which could certainly be used without using actual fixures, granted), and if the test transaction code moves within Rails, that's another integration to worry about.  Or if we add a spec that doesn't wind up making ActiveRecord::TestFixtures load... Or if we decide to use something other than use_db...</p>
<p>So instead I'm using:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#6666ff; font-weight:bold;">Spec::Runner</span>.<span style="color:#9900CC;">configure</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>config<span style="color:#006600; font-weight:bold;">|</span>
  config.<span style="color:#9900CC;">prepend_before</span> <span style="color:#9966CC; font-weight:bold;">do</span>
    <span style="color:#006600; font-weight:bold;">&#40;</span>UseDbPlugin.<span style="color:#9900CC;">all_use_dbs</span> <span style="color:#006600; font-weight:bold;">-</span> <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#6666ff; font-weight:bold;">ActiveRecord::Base</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>db<span style="color:#006600; font-weight:bold;">|</span>
      db.<span style="color:#9900CC;">connection</span>.<span style="color:#9900CC;">increment_open_transactions</span>
      db.<span style="color:#9900CC;">connection</span>.<span style="color:#9900CC;">transaction_joinable</span> = <span style="color:#0000FF; font-weight:bold;">false</span>
      db.<span style="color:#9900CC;">connection</span>.<span style="color:#9900CC;">begin_db_transaction</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  config.<span style="color:#9900CC;">append_after</span> <span style="color:#9966CC; font-weight:bold;">do</span>
    <span style="color:#006600; font-weight:bold;">&#40;</span>UseDbPlugin.<span style="color:#9900CC;">all_use_dbs</span> <span style="color:#006600; font-weight:bold;">-</span> <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#6666ff; font-weight:bold;">ActiveRecord::Base</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">reverse</span>.<span style="color:#9900CC;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>db<span style="color:#006600; font-weight:bold;">|</span>
      db.<span style="color:#9900CC;">connection</span>.<span style="color:#9900CC;">rollback_db_transaction</span>
      db.<span style="color:#9900CC;">connection</span>.<span style="color:#9900CC;">decrement_open_transactions</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>If we weren't already using transactional fixtures, I might pull out the <code lang="ruby">- [ActiveRecord::Base]</code>.  And if we were to change off of use_db, there's one place to change the transaction code.  Finally, there's much less dependence on the innards of ActiveRecord - only it's published API.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.lrdesign.com/2010/03/transactional-testing-for-multiple-databases-in-activerecord/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Danger: ActiveRecord, param hashes, and symbol keys</title>
		<link>http://blog.lrdesign.com/2010/03/danger-activerecord-param-hashes-and-symbol-keys/</link>
		<comments>http://blog.lrdesign.com/2010/03/danger-activerecord-param-hashes-and-symbol-keys/#comments</comments>
		<pubDate>Wed, 10 Mar 2010 22:20:17 +0000</pubDate>
		<dc:creator>Evan</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://blog.lrdesign.com/?p=109</guid>
		<description><![CDATA[Here's a little foible of ActiveRecord that cost me over an hour today. AR accepts both symbol keys and string keys when specifying attributes. Both of these are valid ways of mass assigning attributes to a Rails model: MyModel.new&#40;:field_1 =&#62; 'foo', :field_2 =&#62; 'bar'&#41; MyModel.new&#40;'field_1' =&#62; 'foo', 'field_2' =&#62; 'bar'&#41; It's convenient, often, to not [...]]]></description>
			<content:encoded><![CDATA[<p>Here's a little foible of ActiveRecord that cost me over an hour today.   AR accepts both symbol keys and string keys when specifying attributes.   Both of these are valid ways of mass assigning attributes to a Rails model:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">MyModel.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:field_1</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'foo'</span>, <span style="color:#ff3333; font-weight:bold;">:field_2</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'bar'</span><span style="color:#006600; font-weight:bold;">&#41;</span>
MyModel.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'field_1'</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'foo'</span>, <span style="color:#996600;">'field_2'</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'bar'</span><span style="color:#006600; font-weight:bold;">&#41;</span></pre></div></div>

<p>It's convenient, often, to not have to worry about whether your keys are symbols are strings since they get converted around a bit when you pass parameters.   The downside of this, however, is that it will happily accept BOTH without complaining, and will quietly default to the symbol key regardless of the order you specify them in:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#006600; font-weight:bold;">&gt;&gt;</span> model = MyModel.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:field_1</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'foo'</span>, <span style="color:#996600;">'field_1'</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'bar'</span><span style="color:#006600; font-weight:bold;">&#41;</span>; <span style="color:#0000FF; font-weight:bold;">nil</span>; 
<span style="color:#006600; font-weight:bold;">&gt;&gt;</span> mymodel.<span style="color:#9900CC;">field_1</span>
<span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'foo'</span>
<span style="color:#006600; font-weight:bold;">&gt;&gt;</span> model = MyModel.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'field_1'</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'foo'</span>, <span style="color:#ff3333; font-weight:bold;">:field_1</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'bar'</span><span style="color:#006600; font-weight:bold;">&#41;</span>; <span style="color:#0000FF; font-weight:bold;">nil</span>;
<span style="color:#006600; font-weight:bold;">&gt;&gt;</span> mymodel.<span style="color:#9900CC;">field_1</span>
<span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'bar'</span></pre></div></div>

<h3>Okay, so that's kinda sloppy.  Bad ActiveRecord!  No Biscuit!</h3>
<p>This can cause <em>serious</em> confusion for the unwary.   When ActionController hands us a params hash, it always has String keys, like this:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#006600; font-weight:bold;">&gt;&gt;</span> <span style="color:#CC0066; font-weight:bold;">eval</span> params
<span style="color:#006600; font-weight:bold;">=&gt;</span>  <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#996600;">'article'</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#996600;">'title'</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'Awesome blog post'</span>, <span style="color:#996600;">'body'</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'I will make you smart'</span> <span style="color:#006600; font-weight:bold;">&#125;</span> <span style="color:#006600; font-weight:bold;">&#125;</span></pre></div></div>

<p>But most of us, canonically, specify params and default AR values with symbols, like this:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">   post <span style="color:#ff3333; font-weight:bold;">:article</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#123;</span>:title <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'Awesome blog post'</span>, <span style="color:#ff3333; font-weight:bold;">:body</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'I will make you smart'</span><span style="color:#006600; font-weight:bold;">&#125;</span></pre></div></div>

<p>So we get used to thinking about them as symbols.</p>
<p>This means we can make mistakes like this one I made recently.   Consider this block of code for a shopping cart model that pre-fills some fields for an associated Payment by pulling the address from the user's profile, to save the user re-typing their address:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">class</span> ShoppingCart <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#6666ff; font-weight:bold;">ActiveRecord::Base</span>
  has_one <span style="color:#ff3333; font-weight:bold;">:payment</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> build_default_payment<span style="color:#006600; font-weight:bold;">&#40;</span>options = <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span> 
    <span style="color:#008000; font-style:italic;">#prepopulate the billing address from the profile and merge</span>
    <span style="color:#008000; font-style:italic;">#with params passed into options</span>
    build_payment<span style="color:#006600; font-weight:bold;">&#40;</span>prepopulated_fields.<span style="color:#9900CC;">merge</span>!<span style="color:#006600; font-weight:bold;">&#40;</span>options<span style="color:#006600; font-weight:bold;">&#41;</span>    
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> prepopulated_fields
    <span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#006600; font-weight:bold;">&#40;</span>addr = <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">person</span>.<span style="color:#9900CC;">address</span><span style="color:#006600; font-weight:bold;">&#41;</span>
      <span style="color:#006600; font-weight:bold;">&#123;</span>
        <span style="color:#ff3333; font-weight:bold;">:billing_address_1</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> addr.<span style="color:#9900CC;">line_1</span>,
        <span style="color:#ff3333; font-weight:bold;">:billing_address_2</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> addr.<span style="color:#9900CC;">line_2</span>,
        <span style="color:#ff3333; font-weight:bold;">:city</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> addr.<span style="color:#9900CC;">city</span>,
        <span style="color:#ff3333; font-weight:bold;">:state</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> addr.<span style="color:#9900CC;">state</span>,
        <span style="color:#ff3333; font-weight:bold;">:zip</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> addr.<span style="color:#9900CC;">zipcode</span>
      <span style="color:#006600; font-weight:bold;">&#125;</span>
    <span style="color:#9966CC; font-weight:bold;">else</span>
      <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">&#125;</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>Looks great, right?  And if the user's address has a nil field (like no city, or no line_1), it will get overwritten by the hash merge.</p>
<p>Except not.  I specified symbol keys in prepopulated_fields, but the hash getting passed to build_default_payment's 'options' argument has string keys, because it's coming from params.  So the merge doesn't overwrite the value for :line_1, it simply adds a new key 'line_1'.  So, if a user has a profile address but hadn't entered a line_1 (just city and state), and then manually entered line_1 in the payment form to submit, the Payment build during the create action was getting this hash:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">build_payment<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#123;</span>
   <span style="color:#ff3333; font-weight:bold;">:line_1</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">nil</span>,
   <span style="color:#ff3333; font-weight:bold;">:city</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'Pasadena'</span>,
   <span style="color:#ff3333; font-weight:bold;">:state</span> <span style="color:#006600; font-weight:bold;">=&gt;</span><span style="color:#996600;">'CA'</span>,
   <span style="color:#ff3333; font-weight:bold;">:zipcode</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'91106'</span>
   <span style="color:#996600;">'line_1'</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'100 Main St.'</span>.
<span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span></pre></div></div>

<p>ActiveRecord was respecting the :line_1 => nil from the profile, and not the 'line_1' => '100 Main St.' from params.  This meant that the user couldn't make payment!  The payment had validates_inclusion_of line_1, and even though it was typed into the form it was getting ignored because of the nil from his profile address.   Very frustrating for a user to manually type in a billing address and get back "Address Line 1 can't be blank." on every submit!</p>
<p>Nasty ... this one took a while to figure out.   Beware of this little foible of ActiveRecord!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.lrdesign.com/2010/03/danger-activerecord-param-hashes-and-symbol-keys/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>RailsTutorial.org launched</title>
		<link>http://blog.lrdesign.com/2009/12/railstutorial-org-launched/</link>
		<comments>http://blog.lrdesign.com/2009/12/railstutorial-org-launched/#comments</comments>
		<pubDate>Mon, 14 Dec 2009 18:56:28 +0000</pubDate>
		<dc:creator>Evan</dc:creator>
				<category><![CDATA[Projects]]></category>
		<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://blog.lrdesign.com/?p=83</guid>
		<description><![CDATA[The new Ruby on Rails Tutorial book and website by Michael Hartl has launched at RailsTutorial.org.   Hartl is the author of RailsSpace and cofounder of the Insoshi Ruby on Rails social networking platform. Logical Reality did the logo and layout design work for Rails Tutorial. &#160;]]></description>
			<content:encoded><![CDATA[<p><img class="alignleft size-medium wp-image-84" title="rails-tutorial-logo-2" src="http://blog.lrdesign.com/wp-content/uploads/2009/12/rails-tutorial-logo-2-300x251.png" alt="rails-tutorial-logo-2" width="300" height="251" />The new <a href="http://www.railstutorial.org/">Ruby on Rails Tutorial book</a> and website by Michael Hartl has launched at <a href="http://railstutorial.org/">RailsTutorial.org</a>.   Hartl is the author of RailsSpace and cofounder of the Insoshi Ruby on Rails social networking platform.</p>
<p>Logical Reality did the logo and layout design work for Rails Tutorial.</p>
<div style="clear: both;">&nbsp;</div>
]]></content:encoded>
			<wfw:commentRss>http://blog.lrdesign.com/2009/12/railstutorial-org-launched/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using link_to (or other helper methods) in a controller</title>
		<link>http://blog.lrdesign.com/2009/05/using-link_to-or-other-helper-methods-in-a-controller/</link>
		<comments>http://blog.lrdesign.com/2009/05/using-link_to-or-other-helper-methods-in-a-controller/#comments</comments>
		<pubDate>Wed, 06 May 2009 23:40:10 +0000</pubDate>
		<dc:creator>Evan</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[controllers]]></category>
		<category><![CDATA[helper methods]]></category>
		<category><![CDATA[link_to]]></category>

		<guid isPermaLink="false">http://blog.lrdesign.com/?p=57</guid>
		<description><![CDATA[This one was a big aggravator to me lately. I have one controller that needs to call link_to and url_for, which are normally helper methods you'd call from a view. However, in this case during certain modifications to a record, I actually need to append user-visible HTML links to a block of HTML stored in [...]]]></description>
			<content:encoded><![CDATA[<p>This one was a big aggravator to me lately.   I have one controller that needs to call link_to and url_for, which are normally helper methods you'd call from a view.   However, in this case during certain modifications to a record, I actually need to append user-visible HTML links to a block of HTML stored in that object, or possibly another one.</p>
<p>Specifically, I needed to put annotations in the description of a work order object that said, for example "this work order was escalated from <a href="/tasks/293">Problem Report 293</a>.   This was done in a create action that redirected at the end and never rendered a view, so I really did need to generate that link in the controller.   And for consistency with the rest of the application, I wanted to generate the link with link_to(@task).</p>
<p>Now, ActionView::Helpers::UrlHelper is not loaded in a Rails controller, even if you've put helper :all in application.rb (application_controller.rb in newer versions).   So, when I tried to use link_to in the controller, I got an error:</p>
<p><code>NoMethodError: undefined method `link_to' for #<br />
/Users/evan/Development/Ruby/eclipticdb/app/helpers/tasks_helper.rb:64:in `task_link'<br />
/Users/evan/Development/Ruby/eclipticdb/app/controllers/tasks_controller.rb:103:in `escalate'<br />
... etc ...<br />
</code></p>
<h2>The first fix - but with a problem</h2>
<p>A year ago, I fixed this just by adding <code>include ActionView::Helpers::UrlHelper</code> at the top of that controller.  This worked great ... for a while.</p>
<p>Lately, I've been rewriting this application into a RESTful style - it had previously been a controller/action style application.  In the process, I started linking things with resource paths and polymorphic paths ... a lot of <code>link_to @task</code> and <code>edit_polymorphic_path(@task)</code> sorts of bits.   And these started breaking.   I began seeing this mysterious error:</p>
<h4>Error:</h4>
<p><code>You have a nil object when you didn't expect it!<br />
The error occurred while evaluating nil.url_for</p>
<p>... some code here that calls a link_to ...</p>
<p>Trace of template inclusion: /tasks/_task_panel.html.erb, /tasks/_task_tabbed_panel.html.erb, /tasks/index.html.erb</p>
<p>RAILS_ROOT: /Users/evan/Development/Ruby/eclipticdb<br />
Application Trace | Framework Trace | Full Trace</p>
<p>vendor/rails/actionpack/lib/action_view/helpers/url_helper.rb:71:in `send'<br />
vendor/rails/actionpack/lib/action_view/helpers/url_helper.rb:71:in `url_for'</code></p>
<p>This one was a real bitch to debug, I have to say.   The line in question that was failing in url_helper.rb said this: <code>url = @controller.send(:url_for, options)</code>.   Clearly, @controller was nil ... which was very bizarre, because I never interact with that instance variable anywhere.</p>
<p>I thrashed around trying to find the cause of this error for quite some time.  Eventually I realized that the link_to method was only failing when called from a view in TasksController, and not from any other controller.  And then I realized that TasksController was the one where, a year ago, I'd put <code>include ActionView::Helpers::UrlHelper</code> at the top.   Somehow, including that helper in the controller was nullifying <code>@controller</code> when those helper method we called from within the view.   I removed the include and my polymorphic and resource links all started working again.</p>
<h2>Now back to the original problem!</h2>
<p>Of course, that then left me back with the problem I'd had a year ago ... needing to use link_to from within the controller and having no way to do it.   After a fair bit of googling around I found <a href="http://www.neeraj.name/blog/articles/740-using-helpers-in-controllers">this post</a> from Neeraj, which had an interesting approach -- but a commenter had suggested a much easier solution:</p>
<p>[sourcecode language='ror']self.class.helpers.link_to[/sourcecode]</p>
<p>I'm not certain where one would find this in the docs, but it does seem to have solved my problem for now.  Onward and upward!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.lrdesign.com/2009/05/using-link_to-or-other-helper-methods-in-a-controller/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Single Table Inheritance and RESTful Routes</title>
		<link>http://blog.lrdesign.com/2009/03/single-table-inheritance-and-restful-routes/</link>
		<comments>http://blog.lrdesign.com/2009/03/single-table-inheritance-and-restful-routes/#comments</comments>
		<pubDate>Tue, 17 Mar 2009 21:00:39 +0000</pubDate>
		<dc:creator>Evan</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[REST]]></category>
		<category><![CDATA[RESTful]]></category>
		<category><![CDATA[routes]]></category>
		<category><![CDATA[single table inheritance]]></category>
		<category><![CDATA[STI]]></category>

		<guid isPermaLink="false">http://blog.lrdesign.com/?p=52</guid>
		<description><![CDATA[I'm converting an old, controller/action/id style Rails application to a more RESTful way of doing things, and ran into a brief roadblock: one of my main tables uses single table inheritance to generate three subclasses of items. I never actually use the superclass "task", I only use the three subclasses "action item", "work order", and [...]]]></description>
			<content:encoded><![CDATA[<p>I'm converting an old, controller/action/id style Rails application to a more RESTful way of doing things, and ran into a brief roadblock:   one of my main tables uses single table inheritance to generate three subclasses of items.   I never actually use the superclass "task", I only use the three subclasses "action item", "work order", and "problem report".</p>
<p>So, I ran into this little challenge:  all three STI subclasses use the same controller, "tasks", because they all have essentially the same behavior and differ only in minor details.    But, when I do a resources map:</p>
<p><code>map.resources :tasks</code></p>
<p>Then I get errors in much of my code when I say things like <code>redirect_to @task</code>, because if that task happens to be an ActionItem, it's trying to call <code>action_item_path(@task)</code>, which doesn't exist.</p>
<p>I googled around a bit to no result.  Striking out on my own, it turns out the answer is as simple as mapping each resource independently, and just overriding the controller in map.resources:</p>
<h4>In config/routes.rb</h4>
<p><code>map.resources :tasks<br />
map.resources :action_items, :controller => 'tasks'<br />
map.resources :work_orders, :controller => 'tasks'<br />
map.resources :problem_reports, :controller => 'tasks'<br />
</code></p>
<p>Now, <code>redirect_to @task</code> works just fine regardless of which subclass <code>@task</code> happens to be.   </p>
]]></content:encoded>
			<wfw:commentRss>http://blog.lrdesign.com/2009/03/single-table-inheritance-and-restful-routes/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
		<item>
		<title>Bypassing mass assignment for update_attributes</title>
		<link>http://blog.lrdesign.com/2009/03/bypassing-mass-assignment-for-update_attributes/</link>
		<comments>http://blog.lrdesign.com/2009/03/bypassing-mass-assignment-for-update_attributes/#comments</comments>
		<pubDate>Sat, 14 Mar 2009 21:45:05 +0000</pubDate>
		<dc:creator>Evan</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[Web Security]]></category>
		<category><![CDATA[Active Record]]></category>
		<category><![CDATA[mass assignment]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[update_attributes]]></category>

		<guid isPermaLink="false">http://blog.lrdesign.com/?p=51</guid>
		<description><![CDATA[I've been following this excellent post by M. Hartl and this post by E. Chapweske banishing mass assignment from one of my Rails applications due to launch soon. I'm following Chapweske's approach of blocking mass assignment by default in all models, by putting this line in an initializer: ActiveRecord::Base.send(:attr_accessible, nil) This had the expected side [...]]]></description>
			<content:encoded><![CDATA[<p>I've been following <a href="http://blog.insoshi.com/2008/09/21/finding-and-fixing-mass-assignment-problems-in-rails-applications/#">this excellent post by M. Hartl</a> and <a href="http://railspikes.com/2008/9/22/is-your-rails-application-safe-from-mass-assignment">this post by E. Chapweske</a> banishing mass assignment from one of my Rails applications due to launch soon.</p>
<p>I'm following Chapweske's approach of blocking mass assignment by default in all models, by putting this line in an initializer:</p>
<p><code>ActiveRecord::Base.send(:attr_accessible, nil)</code></p>
<p>This had the expected side effect of breaking several zillion tests, because tests frequently use things like Model.build() and Model.create!() to generate on-demand fixtures during testing.  Hartl has a great bit of code that creates unsafe_build() and unsafe_create() methods in ActiveRecord.   You can use these methods instead of build() and create() to function as expected in your tests.</p>
<p>This works great, except that I also use the mass-assignment method update_attributes! in my tests and specs frequently, particularly when I want to spec the effect a change on one model has on an associated models' methods.   So, I expanded on Hartl's helper code a bit, to give myself the necessary methods.   In case it helps anyone else:</p>
<h4>/lib/initializers/unsafe_build_and_create.rb</h4>
<p><code>class ActiveRecord::Base</p>
<p>  # Build and create records unsafely, bypassing attr_accessible.<br />
  # These methods are especially useful in tests and in the console.</p>
<p>  def self.unsafe_build(attrs)<br />
    record = new<br />
    record.unsafe_attributes = attrs<br />
    record<br />
  end</p>
<p>  def self.unsafe_create(attrs)<br />
    record = unsafe_build(attrs)<br />
    record.save<br />
    record<br />
  end</p>
<p>  def self.unsafe_create!(attrs)<br />
    unsafe_build(attrs).save!<br />
  end</p>
<p>  def unsafe_update_attributes!(attrs)<br />
    self.unsafe_attributes = attrs<br />
    self.save!<br />
  end</p>
<p>  def unsafe_update_attributes(attrs)<br />
    self.unsafe_attributes = attrs<br />
    self.save<br />
  end</p>
<p>  def unsafe_attributes=(attrs)<br />
    attrs.each do |k, v|<br />
      send("#{k}=", v)<br />
    end<br />
  end<br />
end</code></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.lrdesign.com/2009/03/bypassing-mass-assignment-for-update_attributes/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

