<?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: [Rails]  Cleaning up HABTM views (2/2)</title>
	<atom:link href="http://stevengharms.com/rails-cleaning-up-habtm-views-22/feed" rel="self" type="application/rss+xml" />
	<link>http://stevengharms.com/rails-cleaning-up-habtm-views-22</link>
	<description>My Blog</description>
	<lastBuildDate>Sat, 14 Apr 2012 19:47:10 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
	<item>
		<title>By: steven</title>
		<link>http://stevengharms.com/rails-cleaning-up-habtm-views-22/comment-page-1#comment-2246</link>
		<dc:creator>steven</dc:creator>
		<pubDate>Mon, 17 Aug 2009 02:48:51 +0000</pubDate>
		<guid isPermaLink="false">http://stevengharms.net/?p=1084#comment-2246</guid>
		<description>&lt;p&gt;I think that the right place to put that logic would be in the model.&lt;/p&gt;

&lt;p&gt;I &lt;em&gt;generally&lt;/em&gt; consider the model the right place to do any database cross-connection or binding.  Similarly, I consider the controller the right place to either process data before the model is updated into the DB or the right place to treat data before shared with the view.&lt;/p&gt;

&lt;p&gt;I think you might like the Programmatic screencast about advanced forms in Rails done by Ryan Bates. It covers better form modeling technique including controller vs. model issues.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>I think that the right place to put that logic would be in the model.</p>
<p>I <em>generally</em> consider the model the right place to do any database cross-connection or binding.  Similarly, I consider the controller the right place to either process data before the model is updated into the DB or the right place to treat data before shared with the view.</p>
<p>I think you might like the Programmatic screencast about advanced forms in Rails done by Ryan Bates. It covers better form modeling technique including controller vs. model issues.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: T Tally</title>
		<link>http://stevengharms.com/rails-cleaning-up-habtm-views-22/comment-page-1#comment-2236</link>
		<dc:creator>T Tally</dc:creator>
		<pubDate>Fri, 14 Aug 2009 17:38:50 +0000</pubDate>
		<guid isPermaLink="false">http://stevengharms.net/?p=1084#comment-2236</guid>
		<description>&lt;p&gt;Great tutorial but I have one question. Has anyone tried to create records with a HABTM relationship within the View? If so is it best to place that code within the controller or the model?&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Great tutorial but I have one question. Has anyone tried to create records with a HABTM relationship within the View? If so is it best to place that code within the controller or the model?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Peter Hoeg</title>
		<link>http://stevengharms.com/rails-cleaning-up-habtm-views-22/comment-page-1#comment-1887</link>
		<dc:creator>Peter Hoeg</dc:creator>
		<pubDate>Tue, 16 Dec 2008 06:28:25 +0000</pubDate>
		<guid isPermaLink="false">http://stevengharms.net/?p=1084#comment-1887</guid>
		<description>&lt;p&gt;Just a quick comment. Your flavorstring can be boiled down from:&lt;/p&gt;

&lt;p&gt;def flavorstring
  if (self.flavors.length &gt; 0)
    x=String.new()
    self.flavors.uniq.each do &#124;f&#124;
      x += f.name
      x += &quot;, &quot;
    end
    return x.sub(/,s+$/,&#039;&#039;)
  else
    return &quot;&quot;
  end
end&lt;/p&gt;

&lt;p&gt;to:&lt;/p&gt;

&lt;p&gt;def flavorstring
  return self.flavors.uniq.join(&#039;, &#039;)
end&lt;/p&gt;

&lt;p&gt;Flavors really never should be nil but if you insist on checking you can modify it to:&lt;/p&gt;

&lt;p&gt;return self.flavors ? self.flavors.uniq.join.(&#039;, &#039;) : &#039;&#039;&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Just a quick comment. Your flavorstring can be boiled down from:</p>
<p>def flavorstring<br />
  if (self.flavors.length &gt; 0)<br />
    x=String.new()<br />
    self.flavors.uniq.each do |f|<br />
      x += f.name<br />
      x += &#8220;, &#8221;<br />
    end<br />
    return x.sub(/,s+$/,&#8221;)<br />
  else<br />
    return &#8220;&#8221;<br />
  end<br />
end</p>
<p>to:</p>
<p>def flavorstring<br />
  return self.flavors.uniq.join(&#8216;, &#8216;)<br />
end</p>
<p>Flavors really never should be nil but if you insist on checking you can modify it to:</p>
<p>return self.flavors ? self.flavors.uniq.join.(&#8216;, &#8216;) : &#8221;</p>
]]></content:encoded>
	</item>
</channel>
</rss>

