<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title>Astrails - Hi End Web Technology - Latest Comments in Astrails  Let my controller go or useful impurity in software design.</title><link>http://astrails.disqus.com/</link><description>None</description><atom:link href="https://astrails.disqus.com/astrails_let_my_controller_go_or_useful_impurity_in_software_design/latest.rss" rel="self"></atom:link><language>en</language><lastBuildDate>Thu, 12 Nov 2009 20:01:06 -0000</lastBuildDate><item><title>Re: Astrails  Let my controller go or useful impurity in software design.</title><link>http://blog.astrails.com/2009/10/27/liberate-my-controller#comment-22868544</link><description>&lt;p&gt;its is not supported on the console since it is by definition CAN'T be supported on the console. You don't know what domain to use when you are on the console.&lt;br&gt;Where will your urls point to? http://localhost:3000/ ? :)&lt;br&gt;Any other solution will require *some* piece of code holding a current_domain and being responsible for creating nice urls to your models. Since we already have such a piece called "controller" I don't see any reason to duplicate it somewhere else :)&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">astrails</dc:creator><pubDate>Thu, 12 Nov 2009 20:01:06 -0000</pubDate></item><item><title>Re: Astrails  Let my controller go or useful impurity in software design.</title><link>http://blog.astrails.com/2009/10/27/liberate-my-controller#comment-22868467</link><description>&lt;p&gt;I'll tell you why :)&lt;br&gt;Lets say I have articles#index returning Article.paginate(:include =&amp;gt; :comments).to_xml&lt;/p&gt;&lt;p&gt;with current_controller both Article and Comment can access url_for inside their respective to_xml implementations, and all the rest is done by Rails / ActiveSupport&lt;/p&gt;&lt;p&gt;With your presenter pattern I'll have like X times more code that is much harder to understand and maintain. not simpler.&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">astrails</dc:creator><pubDate>Thu, 12 Nov 2009 19:59:10 -0000</pubDate></item><item><title>Re: Astrails  Let my controller go or useful impurity in software design.</title><link>http://blog.astrails.com/2009/10/27/liberate-my-controller#comment-22868401</link><description>&lt;p&gt;presenter will not help for included associations.&lt;br&gt;And having a presenter for every model that I want to return, effectively doubling my class count for the purpose on just to_xml is insane.&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">astrails</dc:creator><pubDate>Thu, 12 Nov 2009 19:57:22 -0000</pubDate></item><item><title>Re: Astrails  Let my controller go or useful impurity in software design.</title><link>http://blog.astrails.com/2009/10/27/liberate-my-controller#comment-22868331</link><description>&lt;p&gt;I do understand MVC, I'm just don't care about 'purity'. I care about 'utility'.&lt;br&gt;'standard' way of implementing respond_to { |w| w.xml ..} in Rails is to call .to_xml.&lt;br&gt;Its the easiest and cleanest (from readability/maintainability/dry/minimal_loc points of view) solution.&lt;br&gt;If you need to generate urls inside it (especially if its in some included association) then having current_controller is IMHO the best possible option.&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">astrails</dc:creator><pubDate>Thu, 12 Nov 2009 19:55:47 -0000</pubDate></item><item><title>Re: Astrails  Let my controller go or useful impurity in software design.</title><link>http://blog.astrails.com/2009/10/27/liberate-my-controller#comment-21167095</link><description>&lt;p&gt;"But sometimes, just sometimes, you need your link_to or html helpers working in the model."&lt;/p&gt;&lt;p&gt;No. It's just stupid when you alter the patterns while there are other ways to accomplish what you need. It just means you don't understand what MVC stands for.&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Jerome</dc:creator><pubDate>Wed, 28 Oct 2009 06:41:07 -0000</pubDate></item><item><title>Re: Astrails  Let my controller go or useful impurity in software design.</title><link>http://blog.astrails.com/2009/10/27/liberate-my-controller#comment-21129905</link><description>&lt;p&gt;+1 ismasan.&lt;/p&gt;&lt;p&gt;Presenter pattern is real nice for this stuff.  Especially when a few months down the road you need to write some script, data migration, cronjob, etc... that wants to use your model outside the rails environment.&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Ryan Angilly</dc:creator><pubDate>Tue, 27 Oct 2009 16:59:22 -0000</pubDate></item><item><title>Re: Astrails  Let my controller go or useful impurity in software design.</title><link>http://blog.astrails.com/2009/10/27/liberate-my-controller#comment-21125078</link><description>&lt;p&gt;Generating a view from your model (to_xml) is the problem here and is the reason why you're needing access to controller methods from your model.&lt;/p&gt;&lt;p&gt;I get around this by having models implement a method called canonical_url that returns an object like so:&lt;/p&gt;&lt;p&gt;&lt;code&gt;{:use_route =&amp;gt; "article", :id =&amp;gt; self.id}&lt;/code&gt;&lt;/p&gt;&lt;p&gt;This hash can then be passed to url_for to generate a route. I think this is a good convention for apps like yours that are doing some CMS-y things and necessarily blurring the line between data and views.&lt;br&gt;&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Chris Eppstein</dc:creator><pubDate>Tue, 27 Oct 2009 16:00:33 -0000</pubDate></item><item><title>Re: Astrails  Let my controller go or useful impurity in software design.</title><link>http://blog.astrails.com/2009/10/27/liberate-my-controller#comment-21123996</link><description>&lt;p&gt;Why couldn't this be a helper and tested with ActionView::TestCase?&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">qrush</dc:creator><pubDate>Tue, 27 Oct 2009 15:46:25 -0000</pubDate></item><item><title>Re: Astrails  Let my controller go or useful impurity in software design.</title><link>http://blog.astrails.com/2009/10/27/liberate-my-controller#comment-21123342</link><description>&lt;p&gt;"i.e. it won’t work from the console".  Yuck.  Since (I'm assuming) you're turning the article into XML for purposes of insertion into a larger document, it seems to me that you'd want to instantiate something else, like an ArticleXmlList, which would have a constructor that accepts a collection of articles and a site domain, that way it has everything it needs to build the list you're looking for.&lt;/p&gt;&lt;p&gt;&lt;a href="http://ArticleXmlList.new" rel="nofollow noopener" target="_blank" title="ArticleXmlList.new"&gt;ArticleXmlList.new&lt;/a&gt;(Article.all, request.domain).to_s&lt;/p&gt;&lt;p&gt;Doesn't use Rails' url helpers, but its easily testable, doesn't know about more than it needs to, and works via the console just fine.&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Bauerpauer</dc:creator><pubDate>Tue, 27 Oct 2009 15:37:02 -0000</pubDate></item><item><title>Re: Astrails  Let my controller go or useful impurity in software design.</title><link>http://blog.astrails.com/2009/10/27/liberate-my-controller#comment-21100755</link><description>&lt;p&gt;I'll be the first then. Why not use the presenter pattern? Something like:&lt;/p&gt;&lt;p&gt;class ArticleWidgetPresenter&lt;/p&gt;&lt;p&gt;  delegate :link_to, :to =&amp;gt; :controller&lt;/p&gt;&lt;p&gt;  def initialize(controller, article_id)&lt;br&gt;    @controller, @article = controller, Article.find(article_id)&lt;br&gt;  end&lt;/p&gt;&lt;p&gt;  def to_html&lt;br&gt;    # .. load a template, build a string, etc&lt;br&gt;  end&lt;br&gt;end&lt;/p&gt;&lt;p&gt;And then, in your controller action&lt;/p&gt;&lt;p&gt;def widget&lt;br&gt;  @presenter = &lt;a href="http://ArticleWidgetPresenter.new" rel="nofollow noopener" target="_blank" title="ArticleWidgetPresenter.new"&gt;ArticleWidgetPresenter.new&lt;/a&gt;(self, params[:id])&lt;br&gt;  render :text =&amp;gt; @presenter.to_html&lt;br&gt;end&lt;/p&gt;&lt;p&gt;You could even load the routing module and not need the controller at all.&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Ismael Celis</dc:creator><pubDate>Tue, 27 Oct 2009 08:34:44 -0000</pubDate></item></channel></rss>