<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	>
<channel>
	<title>Comments on: DRYing up Rails Controllers: Polymorphic and Super Controllers</title>
	<atom:link href="http://www.pathf.com/blogs/2008/07/drying-up-rails-controllers-polymorphic-and-super-controllers/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.pathf.com/blogs/2008/07/drying-up-rails-controllers-polymorphic-and-super-controllers/</link>
	<description>Running commentary about agile development, user experience design and Ajax.</description>
	<pubDate>Fri, 09 Jan 2009 08:42:07 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.5.1</generator>
		<item>
		<title>By: nguma</title>
		<link>http://www.pathf.com/blogs/2008/07/drying-up-rails-controllers-polymorphic-and-super-controllers/#comment-4650</link>
		<dc:creator>nguma</dc:creator>
		<pubDate>Sat, 20 Dec 2008 21:37:25 +0000</pubDate>
		<guid isPermaLink="false">http://www.pathf.com/blogs/?p=1012#comment-4650</guid>
		<description>When it comes down to polymorphism and routing, 
there's one really helpful trick:

polymorphic_url(@my_polymorphic_object)

it will redirect to the correct model, provided you have mapped its resources in routes.rb of course.</description>
		<content:encoded><![CDATA[<p>When it comes down to polymorphism and routing,<br />
there&#8217;s one really helpful trick:</p>
<p>polymorphic_url(@my_polymorphic_object)</p>
<p>it will redirect to the correct model, provided you have mapped its resources in routes.rb of course.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Brett Rasmussen</title>
		<link>http://www.pathf.com/blogs/2008/07/drying-up-rails-controllers-polymorphic-and-super-controllers/#comment-3852</link>
		<dc:creator>Brett Rasmussen</dc:creator>
		<pubDate>Fri, 24 Oct 2008 03:18:25 +0000</pubDate>
		<guid isPermaLink="false">http://www.pathf.com/blogs/?p=1012#comment-3852</guid>
		<description>Josh, in your very first code snippet, you had

class Model &#60; ActiveRecord::Base

but if I'm understanding all of this right, I think you meant

class Comment &#60; ActiveRecord::Base

Also, in the first snippet under "Polymorphic Controllers", you're setting @klass as an instance variable in one line and then using it as just "klass" in the next line.

Just a couple of things I thought you might want to change for the sake of clarity to your readers. But thanks for the article; it was very useful to me.</description>
		<content:encoded><![CDATA[<p>Josh, in your very first code snippet, you had</p>
<p>class Model &lt; ActiveRecord::Base</p>
<p>but if I&#8217;m understanding all of this right, I think you meant</p>
<p>class Comment &lt; ActiveRecord::Base</p>
<p>Also, in the first snippet under &#8220;Polymorphic Controllers&#8221;, you&#8217;re setting @klass as an instance variable in one line and then using it as just &#8220;klass&#8221; in the next line.</p>
<p>Just a couple of things I thought you might want to change for the sake of clarity to your readers. But thanks for the article; it was very useful to me.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dave</title>
		<link>http://www.pathf.com/blogs/2008/07/drying-up-rails-controllers-polymorphic-and-super-controllers/#comment-3454</link>
		<dc:creator>Dave</dc:creator>
		<pubDate>Sat, 27 Sep 2008 10:20:12 +0000</pubDate>
		<guid isPermaLink="false">http://www.pathf.com/blogs/?p=1012#comment-3454</guid>
		<description>Like some other commenters here, I'd prefer included modules over controller inheritance.

Also, I know it's not a real-life expample, but I'd but send_notification_email as an after_update method on the Meeting model itself, or in a MeetingObserver. I don't think it belongs on a controller because it doesn't fundamentally depend on the request.</description>
		<content:encoded><![CDATA[<p>Like some other commenters here, I&#8217;d prefer included modules over controller inheritance.</p>
<p>Also, I know it&#8217;s not a real-life expample, but I&#8217;d but send_notification_email as an after_update method on the Meeting model itself, or in a MeetingObserver. I don&#8217;t think it belongs on a controller because it doesn&#8217;t fundamentally depend on the request.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Little Impact &#187; Blog Archive &#187; Constantize with Care</title>
		<link>http://www.pathf.com/blogs/2008/07/drying-up-rails-controllers-polymorphic-and-super-controllers/#comment-2999</link>
		<dc:creator>Little Impact &#187; Blog Archive &#187; Constantize with Care</dc:creator>
		<pubDate>Wed, 13 Aug 2008 15:38:36 +0000</pubDate>
		<guid isPermaLink="false">http://www.pathf.com/blogs/?p=1012#comment-2999</guid>
		<description>[...] The class parameter is supposed to be Guest, User or Admin. The posted form is supposed to contain a hash of data that initializes the common attributes of them. Using routes we could call http://myapp/vulnerable_basic_data_new/User/. That&#8217;s nice. A google search reveals that quite a lot of people write code like above. [...]</description>
		<content:encoded><![CDATA[<p>[...] The class parameter is supposed to be Guest, User or Admin. The posted form is supposed to contain a hash of data that initializes the common attributes of them. Using routes we could call <a href="http://myapp/vulnerable_basic_data_new/User/" rel="nofollow">http://myapp/vulnerable_basic_data_new/User/</a>. That&#8217;s nice. A google search reveals that quite a lot of people write code like above. [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Never</title>
		<link>http://www.pathf.com/blogs/2008/07/drying-up-rails-controllers-polymorphic-and-super-controllers/#comment-2615</link>
		<dc:creator>Never</dc:creator>
		<pubDate>Thu, 24 Jul 2008 23:05:21 +0000</pubDate>
		<guid isPermaLink="false">http://www.pathf.com/blogs/?p=1012#comment-2615</guid>
		<description>I tried to do the first part (Polymorphic Models and Controllers) but it doesn't quite work for me. I write something into the "body" field and submit but it doesn't show up. I looked at the database and I see that a row actually is added. The commenter_id and commenter_type gets put into the comments table just fine. But the body field is blank. And I don't have attr_accessible anywhere or anything like that..</description>
		<content:encoded><![CDATA[<p>I tried to do the first part (Polymorphic Models and Controllers) but it doesn&#8217;t quite work for me. I write something into the &#8220;body&#8221; field and submit but it doesn&#8217;t show up. I looked at the database and I see that a row actually is added. The commenter_id and commenter_type gets put into the comments table just fine. But the body field is blank. And I don&#8217;t have attr_accessible anywhere or anything like that..</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John</title>
		<link>http://www.pathf.com/blogs/2008/07/drying-up-rails-controllers-polymorphic-and-super-controllers/#comment-2589</link>
		<dc:creator>John</dc:creator>
		<pubDate>Wed, 23 Jul 2008 03:52:26 +0000</pubDate>
		<guid isPermaLink="false">http://www.pathf.com/blogs/?p=1012#comment-2589</guid>
		<description>Instead of inheriting a super controller, you could try adding functionality to the methods with alias_method_chain.</description>
		<content:encoded><![CDATA[<p>Instead of inheriting a super controller, you could try adding functionality to the methods with alias_method_chain.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Matthew Bergman</title>
		<link>http://www.pathf.com/blogs/2008/07/drying-up-rails-controllers-polymorphic-and-super-controllers/#comment-2462</link>
		<dc:creator>Matthew Bergman</dc:creator>
		<pubDate>Wed, 16 Jul 2008 16:48:08 +0000</pubDate>
		<guid isPermaLink="false">http://www.pathf.com/blogs/?p=1012#comment-2462</guid>
		<description>Somehow I feel that this amount of dry code adds more complexity not less. Yes it's more compact but not as easily read. And in the end isn't that what we care about most. Clear concise code?</description>
		<content:encoded><![CDATA[<p>Somehow I feel that this amount of dry code adds more complexity not less. Yes it&#8217;s more compact but not as easily read. And in the end isn&#8217;t that what we care about most. Clear concise code?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: kostia</title>
		<link>http://www.pathf.com/blogs/2008/07/drying-up-rails-controllers-polymorphic-and-super-controllers/#comment-2429</link>
		<dc:creator>kostia</dc:creator>
		<pubDate>Tue, 15 Jul 2008 14:57:39 +0000</pubDate>
		<guid isPermaLink="false">http://www.pathf.com/blogs/?p=1012#comment-2429</guid>
		<description>I'm also not really sure if it is a good idea to let your controllers iherit from some "super"-controller.

You'll be running into some greate problems if you have multiple common functionalities, which has to be shared between controllers. 
For example if you have "comment"-functionality AND "rating"-functionality and you wannt to use sometimes both in the same controller.

I quess a better solution is to put the shared code into a module. In this way you'll get the same dry-up and avoid the side effects of inheritance.</description>
		<content:encoded><![CDATA[<p>I&#8217;m also not really sure if it is a good idea to let your controllers iherit from some &#8220;super&#8221;-controller.</p>
<p>You&#8217;ll be running into some greate problems if you have multiple common functionalities, which has to be shared between controllers.<br />
For example if you have &#8220;comment&#8221;-functionality AND &#8220;rating&#8221;-functionality and you wannt to use sometimes both in the same controller.</p>
<p>I quess a better solution is to put the shared code into a module. In this way you&#8217;ll get the same dry-up and avoid the side effects of inheritance.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: kostia</title>
		<link>http://www.pathf.com/blogs/2008/07/drying-up-rails-controllers-polymorphic-and-super-controllers/#comment-2428</link>
		<dc:creator>kostia</dc:creator>
		<pubDate>Tue, 15 Jul 2008 14:40:18 +0000</pubDate>
		<guid isPermaLink="false">http://www.pathf.com/blogs/?p=1012#comment-2428</guid>
		<description>I quess it's better to use
    @klass = params[:commenter_type].clasify.constantize
instead of
    @klass = params[:commenter_type].capitalize.constantize

"live_user" as commenter_type would otherwise result in something like "Live_user" with capitalize/constantize. In case of clasify/constantize it will become "LiveUser".</description>
		<content:encoded><![CDATA[<p>I quess it&#8217;s better to use<br />
    @klass = params[:commenter_type].clasify.constantize<br />
instead of<br />
    @klass = params[:commenter_type].capitalize.constantize</p>
<p>&#8220;live_user&#8221; as commenter_type would otherwise result in something like &#8220;Live_user&#8221; with capitalize/constantize. In case of clasify/constantize it will become &#8220;LiveUser&#8221;.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Michael Schuerig</title>
		<link>http://www.pathf.com/blogs/2008/07/drying-up-rails-controllers-polymorphic-and-super-controllers/#comment-2391</link>
		<dc:creator>Michael Schuerig</dc:creator>
		<pubDate>Sun, 13 Jul 2008 10:45:35 +0000</pubDate>
		<guid isPermaLink="false">http://www.pathf.com/blogs/?p=1012#comment-2391</guid>
		<description>Please consider that you may be creating a huge security vulnerability by indiscriminately constantizing a string you received in a request. To be on the safe side, you ought to check them against a whitelist.</description>
		<content:encoded><![CDATA[<p>Please consider that you may be creating a huge security vulnerability by indiscriminately constantizing a string you received in a request. To be on the safe side, you ought to check them against a whitelist.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: schorsch</title>
		<link>http://www.pathf.com/blogs/2008/07/drying-up-rails-controllers-polymorphic-and-super-controllers/#comment-2390</link>
		<dc:creator>schorsch</dc:creator>
		<pubDate>Sun, 13 Jul 2008 09:08:56 +0000</pubDate>
		<guid isPermaLink="false">http://www.pathf.com/blogs/?p=1012#comment-2390</guid>
		<description>here's another one for make_resourcefull and RESTfull resources.</description>
		<content:encoded><![CDATA[<p>here&#8217;s another one for make_resourcefull and RESTfull resources.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: supaspoida</title>
		<link>http://www.pathf.com/blogs/2008/07/drying-up-rails-controllers-polymorphic-and-super-controllers/#comment-2385</link>
		<dc:creator>supaspoida</dc:creator>
		<pubDate>Sun, 13 Jul 2008 00:18:47 +0000</pubDate>
		<guid isPermaLink="false">http://www.pathf.com/blogs/?p=1012#comment-2385</guid>
		<description>+1 for make_resourceful, I'm a big fan of it for all my controllers. It gets all the repetition out of the controllers and lets you focus on the parts that are different.</description>
		<content:encoded><![CDATA[<p>+1 for make_resourceful, I&#8217;m a big fan of it for all my controllers. It gets all the repetition out of the controllers and lets you focus on the parts that are different.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jamie Hill</title>
		<link>http://www.pathf.com/blogs/2008/07/drying-up-rails-controllers-polymorphic-and-super-controllers/#comment-2378</link>
		<dc:creator>Jamie Hill</dc:creator>
		<pubDate>Sat, 12 Jul 2008 13:27:49 +0000</pubDate>
		<guid isPermaLink="false">http://www.pathf.com/blogs/?p=1012#comment-2378</guid>
		<description>Good write up. I've been using this recently and found it also helps get rid of duplicate views as you can put generic views in the super controllers path.

One thing, I would use classify instead of capitalize .</description>
		<content:encoded><![CDATA[<p>Good write up. I&#8217;ve been using this recently and found it also helps get rid of duplicate views as you can put generic views in the super controllers path.</p>
<p>One thing, I would use classify instead of capitalize .</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jblanche</title>
		<link>http://www.pathf.com/blogs/2008/07/drying-up-rails-controllers-polymorphic-and-super-controllers/#comment-2374</link>
		<dc:creator>jblanche</dc:creator>
		<pubDate>Sat, 12 Jul 2008 10:42:18 +0000</pubDate>
		<guid isPermaLink="false">http://www.pathf.com/blogs/?p=1012#comment-2374</guid>
		<description>Great post ! 
I think there is another typo in the first code block, the class name for the comment.rb file should be Comment, am i right ?</description>
		<content:encoded><![CDATA[<p>Great post !<br />
I think there is another typo in the first code block, the class name for the comment.rb file should be Comment, am i right ?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Josh Symonds</title>
		<link>http://www.pathf.com/blogs/2008/07/drying-up-rails-controllers-polymorphic-and-super-controllers/#comment-2352</link>
		<dc:creator>Josh Symonds</dc:creator>
		<pubDate>Thu, 10 Jul 2008 15:46:09 +0000</pubDate>
		<guid isPermaLink="false">http://www.pathf.com/blogs/?p=1012#comment-2352</guid>
		<description>Thanks Thierry! See the hazards of copying and pasting? That's why I try to not do it in my code and instead DRY it up, but in examples I have to admit it saves a lot of time. ;)

And also thanks for the heads up on make_resourceful and resource_controller. They look exactly like what the doctor ordered for some serious controller refactoring.</description>
		<content:encoded><![CDATA[<p>Thanks Thierry! See the hazards of copying and pasting? That&#8217;s why I try to not do it in my code and instead DRY it up, but in examples I have to admit it saves a lot of time. <img src='http://www.pathf.com/blogs/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>And also thanks for the heads up on make_resourceful and resource_controller. They look exactly like what the doctor ordered for some serious controller refactoring.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kritikal &#187; Blog Archive &#187; Write less controller code with super and polymorphic controllers</title>
		<link>http://www.pathf.com/blogs/2008/07/drying-up-rails-controllers-polymorphic-and-super-controllers/#comment-2349</link>
		<dc:creator>Kritikal &#187; Blog Archive &#187; Write less controller code with super and polymorphic controllers</dc:creator>
		<pubDate>Thu, 10 Jul 2008 15:10:29 +0000</pubDate>
		<guid isPermaLink="false">http://www.pathf.com/blogs/?p=1012#comment-2349</guid>
		<description>[...] http://www.pathf.com/blogs/2008/07/drying-up-rails-controllers-polymorphic-and-super-controllers/tra... [...]</description>
		<content:encoded><![CDATA[<p>[...] <a href="http://www.pathf.com/blogs/2008/07/drying-up-rails-controllers-polymorphic-and-super-controllers/tra.." rel="nofollow">http://www.pathf.com/blogs/2008/07/drying-up-rails-controllers-polymorphic-and-super-controllers/tra..</a>. [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Thierry</title>
		<link>http://www.pathf.com/blogs/2008/07/drying-up-rails-controllers-polymorphic-and-super-controllers/#comment-2345</link>
		<dc:creator>Thierry</dc:creator>
		<pubDate>Thu, 10 Jul 2008 11:31:52 +0000</pubDate>
		<guid isPermaLink="false">http://www.pathf.com/blogs/?p=1012#comment-2345</guid>
		<description>Very interesting article!
Please note there is a typo in the last source section :
[...]
app/controllers/meetings_controller.rb
class GenericController &#60; ApplicationController
[...]

file should probably be app/controllers/generic_controller.rb</description>
		<content:encoded><![CDATA[<p>Very interesting article!<br />
Please note there is a typo in the last source section :<br />
[...]<br />
app/controllers/meetings_controller.rb<br />
class GenericController &lt; ApplicationController<br />
[...]</p>
<p>file should probably be app/controllers/generic_controller.rb</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Daniel Haran</title>
		<link>http://www.pathf.com/blogs/2008/07/drying-up-rails-controllers-polymorphic-and-super-controllers/#comment-2330</link>
		<dc:creator>Daniel Haran</dc:creator>
		<pubDate>Wed, 09 Jul 2008 13:10:09 +0000</pubDate>
		<guid isPermaLink="false">http://www.pathf.com/blogs/?p=1012#comment-2330</guid>
		<description>http://jamesgolick.com/resource_controller/rdoc/index.html should be of interest to you</description>
		<content:encoded><![CDATA[<p><a href="http://jamesgolick.com/resource_controller/rdoc/index.html" rel="nofollow">http://jamesgolick.com/resource_controller/rdoc/index.html</a> should be of interest to you</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Eric Anderson</title>
		<link>http://www.pathf.com/blogs/2008/07/drying-up-rails-controllers-polymorphic-and-super-controllers/#comment-2328</link>
		<dc:creator>Eric Anderson</dc:creator>
		<pubDate>Wed, 09 Jul 2008 12:30:59 +0000</pubDate>
		<guid isPermaLink="false">http://www.pathf.com/blogs/?p=1012#comment-2328</guid>
		<description>You should look at make_resourceful. It allows you to implement the default controller logic with a single line and has lots of callbacks and hooks to control how this logic works.

Combine make_resoureceful with super controllers and you can really make your code dry. Got a certain set of customizations you do with make_resourceful? Just create a class method in the parent class (usually ApplicationController) that calls make_resourceful with the options you like. You can then have many controllers that are just a simple descriptive line of how they work. You have a little logic in your super controller and then the rest is implemented by make_resourceful.</description>
		<content:encoded><![CDATA[<p>You should look at make_resourceful. It allows you to implement the default controller logic with a single line and has lots of callbacks and hooks to control how this logic works.</p>
<p>Combine make_resoureceful with super controllers and you can really make your code dry. Got a certain set of customizations you do with make_resourceful? Just create a class method in the parent class (usually ApplicationController) that calls make_resourceful with the options you like. You can then have many controllers that are just a simple descriptive line of how they work. You have a little logic in your super controller and then the rest is implemented by make_resourceful.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Alistair Holt</title>
		<link>http://www.pathf.com/blogs/2008/07/drying-up-rails-controllers-polymorphic-and-super-controllers/#comment-2326</link>
		<dc:creator>Alistair Holt</dc:creator>
		<pubDate>Wed, 09 Jul 2008 09:31:56 +0000</pubDate>
		<guid isPermaLink="false">http://www.pathf.com/blogs/?p=1012#comment-2326</guid>
		<description>Very nice. Thanks.</description>
		<content:encoded><![CDATA[<p>Very nice. Thanks.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
