<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css" href="/stylesheets/rss.css"?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>cfis : Reusing Rails Controllers is a Good Thing</title>
    <link>http://cfis.savagexi.com</link>
    <atom:link rel="self" type="application/rss+xml" href="http://cfis.savagexi.com/2008/02/11/reusing-rails-controllers-is-a-good-thing?format=rss"/>
    <language>en-us</language>
    <ttl>40</ttl>
    <description>Charlie Savage's Blog</description>
    <item>
      <title>Comment on Reusing Rails Controllers is a Good Thing by Anders Engstr&#246;m</title>
      <description>&lt;p&gt;Great post.&lt;/p&gt;

&lt;p&gt;I&amp;#8217;ve been avoiding the &amp;#8216;render_component&amp;#8217; stuff purely from what I&amp;#8217;ve read about the awful performance.&lt;/p&gt;

&lt;p&gt;At the same time I&amp;#8217;ve been missing the way Java JSP/Servlets handles &amp;#8220;includes&amp;#8221; - which is superior to the :partial/filter alternative recommended by Rails.&lt;/p&gt;

&lt;p&gt;I will definitely experiment with &amp;#8216;render_component&amp;#8217; to replace my existing mix of &amp;#8220;render :partial&amp;#8221; and &amp;#8220;periodically_call_remote&amp;#8221;.&lt;/p&gt;</description>
      <pubDate>Mon, 11 Feb 2008 12:04:58 -0700</pubDate>
      <guid isPermaLink="false">urn:uuid:9e8bb3d1-b340-48ee-b8c4-78b99985acc3</guid>
      <link>http://cfis.savagexi.com/2008/02/11/reusing-rails-controllers-is-a-good-thing#comment-6567</link>
    </item>
    <item>
      <title>Comment on Reusing Rails Controllers is a Good Thing by Tony Maston</title>
      <description>&lt;p&gt;Code reuse is not a hopeless endeavour unless you have less-than-competent programmers. Reusable controllers are not a pipe dream. My MVC framework for web applications has a set of 30 page controllers which service over 2000 transactions. No only that, but each page is rendered via an XSL stylesheet, and there are only 11 stylesheets in my XSL library. How&amp;#8217;s that for reusability?&lt;/p&gt;

&lt;p&gt;The catch? My framework is not RoR, it is Radicore (&lt;a href="http://www.radicore.org)" rel="nofollow"&gt;http://www.radicore.org)&lt;/a&gt;. It is not written in the Ruby language, it uses PHP. It does not use ActiveRecord, it uses a data dictionary. It does not use an ORM as each object relates directly to a database table.&lt;/p&gt;</description>
      <pubDate>Tue, 12 Feb 2008 02:29:29 -0700</pubDate>
      <guid isPermaLink="false">urn:uuid:dcf2696a-3e86-4fd8-bc58-7ba55a50df7b</guid>
      <link>http://cfis.savagexi.com/2008/02/11/reusing-rails-controllers-is-a-good-thing#comment-6594</link>
    </item>
    <item>
      <title>Comment on Reusing Rails Controllers is a Good Thing by Viktor</title>
      <description>&lt;p&gt;It is not actually unusual to be reusing codes. Especially for practicality&amp;#8217;s sake. It even shows how much talent one has because you get to make codes so versatile.&lt;/p&gt;</description>
      <pubDate>Tue, 12 Feb 2008 05:11:12 -0700</pubDate>
      <guid isPermaLink="false">urn:uuid:7af654e7-dfe9-493b-aff9-dd312af4fbf1</guid>
      <link>http://cfis.savagexi.com/2008/02/11/reusing-rails-controllers-is-a-good-thing#comment-6599</link>
    </item>
    <item>
      <title>Comment on Reusing Rails Controllers is a Good Thing by Peyton </title>
      <description>&lt;p&gt;Thank you for sharing the knowledge on Rails controller. I learned a lot of things regarding this matter. In terms of application, models and views are well explained.&lt;/p&gt;</description>
      <pubDate>Tue, 12 Feb 2008 05:15:03 -0700</pubDate>
      <guid isPermaLink="false">urn:uuid:8839f90d-64da-498a-af84-620e671af471</guid>
      <link>http://cfis.savagexi.com/2008/02/11/reusing-rails-controllers-is-a-good-thing#comment-6600</link>
    </item>
    <item>
      <title>Trackback from Justin's Blog: Widgets are better than components on Reusing Rails Controllers is a Good Thing</title>
      <description>[This article](&lt;a href="http://cfis.savagexi.com/articles/2008/02/11/reusing-rails-controllers-is-a-good-thing" rel="nofollow"&gt;http://cfis.savagexi.com/articles/2008/02/11/reusing-rails-controllers-is-a-good-thing&lt;/a&gt;) made it across my RSS reader today. I ran into my own problem with this while writing a custom CMS for work. We wanted to have reusable componen...</description>
      <pubDate>Tue, 12 Feb 2008 18:10:17 -0700</pubDate>
      <guid isPermaLink="false">urn:uuid:867d55c2-c3cc-48cd-928d-4cd092acafd6</guid>
      <link>http://cfis.savagexi.com/2008/02/11/reusing-rails-controllers-is-a-good-thing#trackback-6631</link>
    </item>
    <item>
      <title>Trackback from Justin's Blog: Sidebars are better than components on Reusing Rails Controllers is a Good Thing</title>
      <description>[This article](&lt;a href="http://cfis.savagexi.com/articles/2008/02/11/reusing-rails-controllers-is-a-good-thing" rel="nofollow"&gt;http://cfis.savagexi.com/articles/2008/02/11/reusing-rails-controllers-is-a-good-thing&lt;/a&gt;) made it across my RSS reader today. I ran into my own problem with this while writing a custom CMS for work. We wanted to have reusable componen...</description>
      <pubDate>Tue, 12 Feb 2008 18:40:02 -0700</pubDate>
      <guid isPermaLink="false">urn:uuid:5b54c97c-cf74-455e-8885-e2671313d72f</guid>
      <link>http://cfis.savagexi.com/2008/02/11/reusing-rails-controllers-is-a-good-thing#trackback-6633</link>
    </item>
    <item>
      <title>Comment on Reusing Rails Controllers is a Good Thing by Piers Cawley</title>
      <description>&lt;p&gt;At work, we&amp;#8217;ve got several independent units on each page and we&amp;#8217;ve taken to wrapping the reusable units up inside helpers.&lt;/p&gt;

&lt;p&gt;The helper&amp;#8217;s then free to do pretty much anything to render its output. It can:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Just render a partial&lt;/li&gt;
&lt;li&gt;Select and then render a partial depending on, say, whether a user is logged in.&lt;/li&gt;
&lt;li&gt;Toddle off to the database and fetch a bunch of objects to render&lt;/li&gt;
&lt;li&gt;Go the whole &lt;code&gt;render_component&lt;/code&gt; hog.&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;The key thing is to pull the act of rendering the partial up into the helper - you write your views to a simple, uniform interface and keep your logic in .rb files.&lt;/p&gt;

&lt;p&gt;I&amp;#8217;d rather see code like:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;&amp;lt;%= comment_widgets @comments %&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;than&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;&amp;lt;%= render :partial =&amp;gt; 'comment', :collection =&amp;gt; @comments %&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;especially when I can implement &lt;code&gt;comment_widgets&lt;/code&gt; and &lt;code&gt;comment_widget&lt;/code&gt; in a declarative style like:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;widget :comment
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Implementation of &lt;code&gt;widget&lt;/code&gt; is left as an exercise for the interested reader; it&amp;#8217;s not exactly tricky.&lt;/p&gt;</description>
      <pubDate>Wed, 13 Feb 2008 00:53:52 -0700</pubDate>
      <guid isPermaLink="false">urn:uuid:cd5cfb19-3d39-4fee-81b6-f89aec34bdbc</guid>
      <link>http://cfis.savagexi.com/2008/02/11/reusing-rails-controllers-is-a-good-thing#comment-6636</link>
    </item>
    <item>
      <title>Comment on Reusing Rails Controllers is a Good Thing by Charlie</title>
      <description>&lt;p&gt;Hi Tony,&lt;/p&gt;

&lt;p&gt;Actually I think its the other way around - code reuse is only possible if you have competent programmers.&lt;/p&gt;

&lt;p&gt;For &lt;a href="http://cfis.savagexi.com/articles/2006/03/21/rest-leading-to-rails" rel="nofollow"&gt;SIAS&lt;/a&gt;, we used XSL stylesheets on the server side to convert XML to HTML.  It would have been great to move the XSL transformation to the client, but back then there was no way it was going to work. In the end I&amp;#8217;ve moved away from XSL, because writing programs in XML is fairly awful.  What have your experiences been?&lt;/p&gt;</description>
      <pubDate>Wed, 13 Feb 2008 02:47:05 -0700</pubDate>
      <guid isPermaLink="false">urn:uuid:51b283e7-77c2-4baf-b27e-a821650f6e26</guid>
      <link>http://cfis.savagexi.com/2008/02/11/reusing-rails-controllers-is-a-good-thing#comment-6637</link>
    </item>
    <item>
      <title>Comment on Reusing Rails Controllers is a Good Thing by Charlie</title>
      <description>&lt;p&gt;Viktor - So I take it you&amp;#8217;re not a believer in &lt;a href="http://en.wikipedia.org/wiki/You_Ain't_Gonna_Need_It" rel="nofollow"&gt;YAGNI&lt;/a&gt;?&lt;/p&gt;

&lt;p&gt;Obviously code reuse is a good thing within an application - it just seems that fact was lost in the Rails community in the big hubbub over components.&lt;/p&gt;</description>
      <pubDate>Wed, 13 Feb 2008 02:51:07 -0700</pubDate>
      <guid isPermaLink="false">urn:uuid:9c992798-ced1-4faa-805e-ed5a3aad84e1</guid>
      <link>http://cfis.savagexi.com/2008/02/11/reusing-rails-controllers-is-a-good-thing#comment-6638</link>
    </item>
    <item>
      <title>Comment on Reusing Rails Controllers is a Good Thing by Charlie</title>
      <description>&lt;p&gt;Hey Peyton - No problem&amp;#8230;&lt;/p&gt;</description>
      <pubDate>Wed, 13 Feb 2008 02:51:43 -0700</pubDate>
      <guid isPermaLink="false">urn:uuid:439d8088-8742-4774-86e1-85f8f3fb984d</guid>
      <link>http://cfis.savagexi.com/2008/02/11/reusing-rails-controllers-is-a-good-thing#comment-6639</link>
    </item>
    <item>
      <title>Comment on Reusing Rails Controllers is a Good Thing by Charlie</title>
      <description>&lt;p&gt;Welcome back Piers - I was hoping you&amp;#8217;d share your experiences with Typo and the move away from using sidebar controllers to using a system based on partials.  Did you draw any conclusions in the process?&lt;/p&gt;

&lt;p&gt;As far as using helpers instead of partials I&amp;#8217;m torn.  I see where you are coming from, but I really find generating HTML using ERB much more pleasant.  I suppose you&amp;#8217;d point on that you just have your helper render the partial, but then you&amp;#8217;re adding an extra level on indirection that doesn&amp;#8217;t gain you much.&lt;/p&gt;

&lt;p&gt;You&amp;#8217;re only one step away from self rendering &lt;a href="http://blog.caboo.se/articles/2007/4/8/heresy-and-turtles-all-the-way-down-with-avi-bryant" rel="nofollow"&gt;components&lt;/a&gt; though&amp;#8230;&lt;/p&gt;</description>
      <pubDate>Wed, 13 Feb 2008 02:57:56 -0700</pubDate>
      <guid isPermaLink="false">urn:uuid:831de8a1-dbba-419d-8e10-e8a77dfdcca2</guid>
      <link>http://cfis.savagexi.com/2008/02/11/reusing-rails-controllers-is-a-good-thing#comment-6640</link>
    </item>
    <item>
      <title>Comment on Reusing Rails Controllers is a Good Thing by Piers Cawley</title>
      <description>&lt;p&gt;I&amp;#8217;m not sure that self rendering components is a particularly bad way to go though. I&amp;#8217;m not a big fan of templating in general and ERB in particular - I prefer Haml for my personal work because it DRYs up so much of the noise of HTML/ERB, which helps you see ugliness in the code that much quicker.&lt;/p&gt;

&lt;p&gt;I think it&amp;#8217;s instructive too, to think about how you&amp;#8217;d go about implementing something like Facebook in rails, where pages like the profile page are pretty much entirely componentized. You&amp;#8217;re pretty much obliged to have some kind of component system where components know how to render themselves independently of the rest of the page.&lt;/p&gt;

&lt;p&gt;Typo&amp;#8217;s sidebars are a cut down version of this approach - the best trick they have up their sleeves, to my way of thinking anyway is the way their configuration system works. There&amp;#8217;s a standardised set of setting types which allows an administrative view to reflect on the sidebar&amp;#8217;s class and generate a form for each instance of the sidebar. I&amp;#8217;m still rather proud of that. I&amp;#8217;m thinking of extending it to a wider typo plugin system which will fire callbacks at various points in the request/render cycle, allowing plugins to customize various almost any aspect of the process. The use case I have in mind is a plugin to implement captchas, both because a captcha system will go into typo&amp;#8217;s core over my cold dead body and because a well implemented captcha scheme needs to plug into various parts of the request/render cycle.&lt;/p&gt;

&lt;p&gt;Which is tangential to what you&amp;#8217;re writing about, but, I hope, still interesting.&lt;/p&gt;</description>
      <pubDate>Thu, 14 Feb 2008 11:05:53 -0700</pubDate>
      <guid isPermaLink="false">urn:uuid:8d7676fb-84ee-45ac-ad0a-40b0a6b1cf2b</guid>
      <link>http://cfis.savagexi.com/2008/02/11/reusing-rails-controllers-is-a-good-thing#comment-6681</link>
    </item>
    <item>
      <title>Comment on Reusing Rails Controllers is a Good Thing by Stijn</title>
      <description>&lt;p&gt;I ran into this article the other day : &lt;a href="http://kurt.karmalab.org/articles/2008/02/13/bringing-components-back-into-rails-with-cells" rel="nofollow"&gt;http://kurt.karmalab.org/articles/2008/02/13/bringing-components-back-into-rails-with-cells&lt;/a&gt;
It&amp;#8217;s about a plugin &amp;#8216;cells&amp;#8217; (&lt;a href="http://cells.rubyforge.org/" rel="nofollow"&gt;http://cells.rubyforge.org/&lt;/a&gt;)&lt;/p&gt;

&lt;p&gt;Seems like a neat solution for the whole &amp;#8220;rails components&amp;#8221; issue.&lt;/p&gt;

&lt;p&gt;It depends on the engines-plugin (&lt;a href="http://www.rails-engines.org/)" rel="nofollow"&gt;http://www.rails-engines.org/)&lt;/a&gt;, which looks quite &amp;#8220;heavy&amp;#8221;. Anybody experience with this ?&lt;/p&gt;</description>
      <pubDate>Fri, 15 Feb 2008 06:13:29 -0700</pubDate>
      <guid isPermaLink="false">urn:uuid:14ce0c7f-75dd-4cbc-b2ea-12e498706671</guid>
      <link>http://cfis.savagexi.com/2008/02/11/reusing-rails-controllers-is-a-good-thing#comment-6764</link>
    </item>
    <item>
      <title>Comment on Reusing Rails Controllers is a Good Thing by Peter Bex</title>
      <description>&lt;p&gt;Actually, Engines is not heavy at all, especially since Rails 2.  It&amp;#8217;s basically regular Rails Plugins with some monkeypatching of the class finding methods, nothing more.&lt;/p&gt;

&lt;p&gt;Also, the main reason &amp;#8220;components&amp;#8221; are slow is that (afaik) you can&amp;#8217;t pass complete objects to them.  This would mean you create a wall between your current controller and the one you&amp;#8217;re rendering as a component, which means you will need to hit the database everytime you want to use the same object in different components.  &lt;em&gt;this&lt;/em&gt; is the main performance bottleneck: the request stack only allows you to pass strings (via the params hash)&lt;/p&gt;

&lt;p&gt;Cells do not have this problem, you can just pass &lt;em&gt;real objects&lt;/em&gt; to the Cells.  Besides performance this has the benefit of being able to pass modified-but-not-yet-saved objects to the components (for rendering validation errors, for example, something I&amp;#8217;ve done in a Cells-using project of mine)&lt;/p&gt;</description>
      <pubDate>Tue, 26 Feb 2008 02:01:39 -0700</pubDate>
      <guid isPermaLink="false">urn:uuid:2da0525a-a4aa-4eba-9ed3-c48d3763ab1a</guid>
      <link>http://cfis.savagexi.com/2008/02/11/reusing-rails-controllers-is-a-good-thing#comment-7474</link>
    </item>
    <item>
      <title>Comment on Reusing Rails Controllers is a Good Thing by Anton</title>
      <description>&lt;p&gt;Now that REST is the core of Rails 2.0 its even more an issue to think about render_component.
I personaly have the impression it slows dones the performance more than 50% but however. I am using it even I am not really happy with the req/sec.&lt;/p&gt;

&lt;p&gt;It would be good to know how you can tune it at least a little bit and still following DRY and REST.&lt;/p&gt;</description>
      <pubDate>Tue, 04 Mar 2008 01:59:50 -0700</pubDate>
      <guid isPermaLink="false">urn:uuid:e9727300-8911-4bb4-a760-bdc83d32b7da</guid>
      <link>http://cfis.savagexi.com/2008/02/11/reusing-rails-controllers-is-a-good-thing#comment-8046</link>
    </item>
  </channel>
</rss>
