<?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"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<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>
	<lastBuildDate>Fri, 05 Mar 2010 19:33:43 -0600</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
	<item>
		<title>By: telefon dinleme</title>
		<link>http://www.pathf.com/blogs/2008/07/drying-up-rails-controllers-polymorphic-and-super-controllers/comment-page-1/#comment-7204</link>
		<dc:creator>telefon dinleme</dc:creator>
		<pubDate>Sun, 09 Aug 2009 00:54:57 +0000</pubDate>
		<guid isPermaLink="false">http://www.pathf.com/blogs/?p=1012#comment-7204</guid>
		<description>thank you for your article. i find it after to 1 month... good evening..</description>
		<content:encoded><![CDATA[<p>thank you for your article. i find it after to 1 month&#8230; good evening..</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Swards</title>
		<link>http://www.pathf.com/blogs/2008/07/drying-up-rails-controllers-polymorphic-and-super-controllers/comment-page-1/#comment-6840</link>
		<dc:creator>Swards</dc:creator>
		<pubDate>Sun, 28 Jun 2009 21:54:10 +0000</pubDate>
		<guid isPermaLink="false">http://www.pathf.com/blogs/?p=1012#comment-6840</guid>
		<description>Great - All the ERB was removed.  I&#039;ll do a larger write up and post elsewhere - I&#039;ll link back.</description>
		<content:encoded><![CDATA[<p>Great &#8211; All the ERB was removed.  I&#8217;ll do a larger write up and post elsewhere &#8211; I&#8217;ll link back.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Swards</title>
		<link>http://www.pathf.com/blogs/2008/07/drying-up-rails-controllers-polymorphic-and-super-controllers/comment-page-1/#comment-6839</link>
		<dc:creator>Swards</dc:creator>
		<pubDate>Sun, 28 Jun 2009 21:49:36 +0000</pubDate>
		<guid isPermaLink="false">http://www.pathf.com/blogs/?p=1012#comment-6839</guid>
		<description>There&#039;s a simpler way. If you make the comment form a partial and do this instead:


  
  
  etc...


(Note the [@commentable, @comment])

 &#039;comment_form&#039;, :locals =&gt; { :commentable =&gt; @user} %&gt;

You don&#039;t need to deal with @klass, constantize, etc.

And, in the comments controller, do something like this:

def create
  @comment = Comment.new(params[:comment])
  @commentable = @comment.commentable
  @comment.save
  ...
end</description>
		<content:encoded><![CDATA[<p>There&#8217;s a simpler way. If you make the comment form a partial and do this instead:</p>
<p>  etc&#8230;</p>
<p>(Note the [@commentable, @comment])</p>
<p> &#8216;comment_form&#8217;, :locals =&gt; { :commentable =&gt; @user} %&gt;</p>
<p>You don&#8217;t need to deal with @klass, constantize, etc.</p>
<p>And, in the comments controller, do something like this:</p>
<p>def create<br />
  @comment = Comment.new(params[:comment])<br />
  @commentable = @comment.commentable<br />
  @comment.save<br />
  &#8230;<br />
end</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: links for 2009-05-18 &#124; NeXt</title>
		<link>http://www.pathf.com/blogs/2008/07/drying-up-rails-controllers-polymorphic-and-super-controllers/comment-page-1/#comment-6748</link>
		<dc:creator>links for 2009-05-18 &#124; NeXt</dc:creator>
		<pubDate>Wed, 17 Jun 2009 19:01:59 +0000</pubDate>
		<guid isPermaLink="false">http://www.pathf.com/blogs/?p=1012#comment-6748</guid>
		<description>[...] Agile Ajax » DRYing up Rails Controllers: Polymorphic and Super Controllers » Pathfinder Developme... (tags: programming tutorial patterns agile controller ruby rails) [...]</description>
		<content:encoded><![CDATA[<p>[...] Agile Ajax » DRYing up Rails Controllers: Polymorphic and Super Controllers » Pathfinder Developme&#8230; (tags: programming tutorial patterns agile controller ruby rails) [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: huberto</title>
		<link>http://www.pathf.com/blogs/2008/07/drying-up-rails-controllers-polymorphic-and-super-controllers/comment-page-1/#comment-6601</link>
		<dc:creator>huberto</dc:creator>
		<pubDate>Fri, 05 Jun 2009 00:37:39 +0000</pubDate>
		<guid isPermaLink="false">http://www.pathf.com/blogs/?p=1012#comment-6601</guid>
		<description>thanks. this was just what i needed to get through my issue. i was thinking about doing something along these lines to dry up my controllers but felt that this might be a bit hackish and cause me great pain down the road. this reassures that&#039;s not the case. 

one thought though, wouldn&#039;t something like this be cleaner? 

in the view:

render :partial =&gt; &#039;comments_form&#039; :object =&gt; @object_to_be_commented_on

and then call comments_form.class.to_s to generate the string constant from inside the comments_form partial?

-h</description>
		<content:encoded><![CDATA[<p>thanks. this was just what i needed to get through my issue. i was thinking about doing something along these lines to dry up my controllers but felt that this might be a bit hackish and cause me great pain down the road. this reassures that&#8217;s not the case. </p>
<p>one thought though, wouldn&#8217;t something like this be cleaner? </p>
<p>in the view:</p>
<p>render :partial =&gt; &#8216;comments_form&#8217; <img src='http://www.pathf.com/blogs/wp-includes/images/smilies/icon_surprised.gif' alt=':o' class='wp-smiley' /> bject =&gt; @object_to_be_commented_on</p>
<p>and then call comments_form.class.to_s to generate the string constant from inside the comments_form partial?</p>
<p>-h</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: André Durão</title>
		<link>http://www.pathf.com/blogs/2008/07/drying-up-rails-controllers-polymorphic-and-super-controllers/comment-page-1/#comment-6514</link>
		<dc:creator>André Durão</dc:creator>
		<pubDate>Mon, 25 May 2009 14:30:49 +0000</pubDate>
		<guid isPermaLink="false">http://www.pathf.com/blogs/?p=1012#comment-6514</guid>
		<description>Hi there!
I found your topic very interesting, and help me a lot to understand polymorphism in rails..
I just got one question, maybe you know what I&#039;m doing wrong:
In my case I would like to use a has_one instead of has_many in my models, but it didn&#039;t worked, just with has_many it worked, is that some limitation of :as option?
thanks</description>
		<content:encoded><![CDATA[<p>Hi there!<br />
I found your topic very interesting, and help me a lot to understand polymorphism in rails..<br />
I just got one question, maybe you know what I&#8217;m doing wrong:<br />
In my case I would like to use a has_one instead of has_many in my models, but it didn&#8217;t worked, just with has_many it worked, is that some limitation of :as option?<br />
thanks</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Matt Simpson</title>
		<link>http://www.pathf.com/blogs/2008/07/drying-up-rails-controllers-polymorphic-and-super-controllers/comment-page-1/#comment-6399</link>
		<dc:creator>Matt Simpson</dc:creator>
		<pubDate>Sun, 03 May 2009 08:01:54 +0000</pubDate>
		<guid isPermaLink="false">http://www.pathf.com/blogs/?p=1012#comment-6399</guid>
		<description>Great article, just what I was looking for.  Including all of the comments for how to enhance this method.  My controllers are going to be beautifully DRY! :o</description>
		<content:encoded><![CDATA[<p>Great article, just what I was looking for.  Including all of the comments for how to enhance this method.  My controllers are going to be beautifully DRY! <img src='http://www.pathf.com/blogs/wp-includes/images/smilies/icon_surprised.gif' alt=':o' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: mitch</title>
		<link>http://www.pathf.com/blogs/2008/07/drying-up-rails-controllers-polymorphic-and-super-controllers/comment-page-1/#comment-6120</link>
		<dc:creator>mitch</dc:creator>
		<pubDate>Tue, 24 Mar 2009 06:11:54 +0000</pubDate>
		<guid isPermaLink="false">http://www.pathf.com/blogs/?p=1012#comment-6120</guid>
		<description>Nice discussion and examples. I do think dry can be taken too far when it means using inheritance just to isolate code. I mean, why should a User and a Meeting both inherit from the same class just because some of their methods have similar code? I agree that a module would be more appropriate.</description>
		<content:encoded><![CDATA[<p>Nice discussion and examples. I do think dry can be taken too far when it means using inheritance just to isolate code. I mean, why should a User and a Meeting both inherit from the same class just because some of their methods have similar code? I agree that a module would be more appropriate.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: nguma</title>
		<link>http://www.pathf.com/blogs/2008/07/drying-up-rails-controllers-polymorphic-and-super-controllers/comment-page-1/#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&#039;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-page-1/#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 &lt; ActiveRecord::Base

but if I&#039;m understanding all of this right, I think you meant

class Comment &lt; ActiveRecord::Base

Also, in the first snippet under &quot;Polymorphic Controllers&quot;, you&#039;re setting @klass as an instance variable in one line and then using it as just &quot;klass&quot; 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-page-1/#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&#039;d prefer included modules over controller inheritance.

Also, I know it&#039;s not a real-life expample, but I&#039;d but send_notification_email as an after_update method on the Meeting model itself, or in a MeetingObserver. I don&#039;t think it belongs on a controller because it doesn&#039;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-page-1/#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-page-1/#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&#039;t quite work for me. I write something into the &quot;body&quot; field and submit but it doesn&#039;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&#039;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-page-1/#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-page-1/#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&#039;s more compact but not as easily read. And in the end isn&#039;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-page-1/#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&#039;m also not really sure if it is a good idea to let your controllers iherit from some &quot;super&quot;-controller.

You&#039;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 &quot;comment&quot;-functionality AND &quot;rating&quot;-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&#039;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-page-1/#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&#039;s better to use
    @klass = params[:commenter_type].clasify.constantize
instead of
    @klass = params[:commenter_type].capitalize.constantize

&quot;live_user&quot; as commenter_type would otherwise result in something like &quot;Live_user&quot; with capitalize/constantize. In case of clasify/constantize it will become &quot;LiveUser&quot;.</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-page-1/#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-page-1/#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&#039;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-page-1/#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&#039;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>
</channel>
</rss>

<!-- Dynamic page generated in 0.360 seconds. -->
<!-- Cached page generated by WP-Super-Cache on 2010-03-22 08:11:57 -->
