<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-7989393224589793489</id><updated>2012-02-16T03:34:59.561-07:00</updated><category term='ruby'/><category term='mvc'/><category term='rails'/><title type='text'>This Old Coder</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://thisoldcoder.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7989393224589793489/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://thisoldcoder.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Paul Watson</name><uri>http://www.blogger.com/profile/10568772235271073557</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://bp3.blogger.com/_KyA1uNf0Ulo/R3adYmzxt5I/AAAAAAAAAAM/DBk3A06DPHs/S220/facebook_75x75.jpeg'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>1</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-7989393224589793489.post-6096199620608143384</id><published>2007-12-28T19:40:00.000-07:00</published><updated>2007-12-29T15:45:21.965-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='ruby'/><category scheme='http://www.blogger.com/atom/ns#' term='rails'/><category scheme='http://www.blogger.com/atom/ns#' term='mvc'/><title type='text'>Food Goes In Here</title><content type='html'>There's an episode of The Simpsons where Homer's inner-child point's to his mouth saying "Food goes in here." To which Homer replies "It sure does."&lt;br /&gt;&lt;br /&gt;&lt;table&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;&lt;span style="FONT-WEIGHT: bold"&gt;Model&lt;/span&gt;&lt;br /&gt;&lt;span style="FONT-WEIGHT: bold"&gt;View&lt;/span&gt;&lt;br /&gt;&lt;span style="FONT-WEIGHT: bold"&gt;Controller&lt;/span&gt;&lt;/td&gt;&lt;td style="VERTICAL-ALIGN: top"&gt;&amp;lt;= Business logic goes in here&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;It sure does.&lt;br /&gt;&lt;br /&gt;As a general rule I avoid blogging about the obvious, but sometimes what's obvious varies from person to person. I've run into the misconception that Rails does not support this obvious statement, that business logic goes into the Model. In Rails, according to this misconception, the Model is simply a Data Access Layer, and business logic winds up in the helpers or elsewhere. The purpose of this post is mainly to give me something to link to or copy and paste as the mood strikes me when I next run into this misconception.&lt;br /&gt;&lt;br /&gt;In Ruby on Rails, as in any good MVC framework, business logic goes in the Model. All of it. Every shred of it.&lt;br /&gt;&lt;br /&gt;I'm currently working on a project to develop a point-of-sale and online purchasing system with a great deal of very complex (some might argue overly complex) business logic. Simply displaying the available quantity of a specific item involves considering at which warehouse the order is being fulfilled, the quantities in various bins, and quantities from the bins which have already been allocated to an order but not yet pulled.&lt;br /&gt;&lt;br /&gt;None of that business logic is in the Controller. None of it is in the View. And none of it is in a helper. It's all in the Model. The only thing the View needs to do is this:&lt;div class="CodeRay"&gt;&lt;br /&gt;  &lt;div class="code"&gt;&lt;pre&gt;item.quantity_available&lt;br /&gt;&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;&lt;/div&gt;I'm not sure where this notion that business logic goes in the helper comes from. For the record:&lt;br /&gt;&lt;blockquote&gt;A &lt;span style="FONT-STYLE: italic"&gt;helper&lt;/span&gt; is simply a module containing methods that assist a view. Helper methods are output-centric. They exist to generate HTML (or XML, or JavaScript) -- a helper extends the behavior of a template.&lt;br /&gt;&lt;br /&gt;-- &lt;u&gt;Agile Web Development With Rails&lt;/u&gt;, Dave Thomas, David Heinemeier Hansson&lt;br /&gt;&lt;/blockquote&gt;Put another way, you can off-load code to the helper to avoid putting too much into your View templates.&lt;br /&gt;&lt;br /&gt;For further reading on this topic, here's a few handy links:&lt;br /&gt;&lt;ul&gt;&lt;li&gt;&lt;a href="http://weblog.jamisbuck.org/2006/10/18/skinny-controller-fat-model"&gt;Skinny Controller, Fat Model&lt;/a&gt; by Jamis Buck&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.therailsway.com/2007/6/1/railsconf-recap-skinny-controllers"&gt;RailsConf Recap: Skinny Controllers&lt;/a&gt; by Jamis Buck&lt;/li&gt;&lt;li&gt;&lt;a href="http://blog.kineticweb.com/articles/2007/06/01/skinny-controller-fat-model"&gt;Skinny Controller, Fat Model&lt;/a&gt; by Colin A. Bartlett&lt;br /&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://blog.imperialdune.com/2007/4/19/find-methods-in-controllers"&gt;Find methods in controllers&lt;/a&gt; by Graeme Nelson&lt;/li&gt;&lt;li&gt;&lt;a href="http://blog.caboo.se/articles/2007/6/19/rspec-notes-from-the-trenches-2"&gt;Rspec notes from the trenches-2&lt;/a&gt; by Courtenay over on Caboo.se &lt;/li&gt;&lt;/ul&gt;&lt;h1&gt;&lt;/h1&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7989393224589793489-6096199620608143384?l=thisoldcoder.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thisoldcoder.blogspot.com/feeds/6096199620608143384/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7989393224589793489&amp;postID=6096199620608143384' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7989393224589793489/posts/default/6096199620608143384'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7989393224589793489/posts/default/6096199620608143384'/><link rel='alternate' type='text/html' href='http://thisoldcoder.blogspot.com/2007/12/food-goes-in-here.html' title='Food Goes In Here'/><author><name>Paul Watson</name><uri>http://www.blogger.com/profile/10568772235271073557</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://bp3.blogger.com/_KyA1uNf0Ulo/R3adYmzxt5I/AAAAAAAAAAM/DBk3A06DPHs/S220/facebook_75x75.jpeg'/></author><thr:total>0</thr:total></entry></feed>
