<?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: What&#8217;s the best way to handle my lists?</title>
	<atom:link href="http://donttrustthisguy.com/2006/08/24/rails-whats-the-best-way-to-handle-my-lists/feed/" rel="self" type="application/rss+xml" />
	<link>http://donttrustthisguy.com/2006/08/24/rails-whats-the-best-way-to-handle-my-lists/</link>
	<description>Why not take my word for it?</description>
	<lastBuildDate>Wed, 07 Apr 2010 23:55:29 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: seasonfive</title>
		<link>http://donttrustthisguy.com/2006/08/24/rails-whats-the-best-way-to-handle-my-lists/comment-page-1/#comment-4344</link>
		<dc:creator>seasonfive</dc:creator>
		<pubDate>Fri, 04 May 2007 18:36:41 +0000</pubDate>
		<guid isPermaLink="false">http://www.donttrustthisguy.com/2006/08/24/rails-whats-the-best-way-to-handle-my-lists/#comment-4344</guid>
		<description>Last try ...

&lt;pre name=&quot;code&quot; class=&quot;ruby&quot;&gt;
class Content &lt; ActiveRecord::Base
  has_one     :picture, :as =&gt; :gallery 
end

class Picture &lt; ActiveRecord::Base
  belongs_to  :gallery, :polymorphic =&gt; true 
end
&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>Last try &#8230;</p>
<pre name="code" class="ruby">
class Content &lt; ActiveRecord::Base
  has_one     :picture, :as =&gt; :gallery
end

class Picture &lt; ActiveRecord::Base
  belongs_to  :gallery, :polymorphic =&gt; true
end
</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: seasonfive</title>
		<link>http://donttrustthisguy.com/2006/08/24/rails-whats-the-best-way-to-handle-my-lists/comment-page-1/#comment-4343</link>
		<dc:creator>seasonfive</dc:creator>
		<pubDate>Fri, 04 May 2007 18:35:33 +0000</pubDate>
		<guid isPermaLink="false">http://www.donttrustthisguy.com/2006/08/24/rails-whats-the-best-way-to-handle-my-lists/#comment-4343</guid>
		<description>Arghhh none of the class pasted well ... Sorry to poluate your blog man. I would be able to edit my post but i can&#039;t. Here the Content and Car model which could have Picture :

&lt;pre name=&quot;code&quot; class=&quot;ruby&quot;&gt;
class Car  :gallery
  ....
end

class Content  :gallery 
  ....
end
&lt;/pre&gt;

</description>
		<content:encoded><![CDATA[<p>Arghhh none of the class pasted well &#8230; Sorry to poluate your blog man. I would be able to edit my post but i can&#8217;t. Here the Content and Car model which could have Picture :</p>
<pre name="code" class="ruby">
class Car  :gallery
  ....
end

class Content  :gallery
  ....
end
</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: seasonfive</title>
		<link>http://donttrustthisguy.com/2006/08/24/rails-whats-the-best-way-to-handle-my-lists/comment-page-1/#comment-4342</link>
		<dc:creator>seasonfive</dc:creator>
		<pubDate>Fri, 04 May 2007 18:34:06 +0000</pubDate>
		<guid isPermaLink="false">http://www.donttrustthisguy.com/2006/08/24/rails-whats-the-best-way-to-handle-my-lists/#comment-4342</guid>
		<description>Sorry for the double post but seems my Picture model wasn&#039;t pasted correctly :-p

&lt;pre name=&quot;code&quot; class=&quot;ruby&quot;&gt;
class Picture  true  
  file_column :file, :magick =&gt; {
                        :versions =&gt; {  ...  }
    }
    
  acts_as_list  :scope =&gt; &#039;gallery_type = \&#039;#{gallery_type}\&#039; AND gallery_id = \&#039;#{gallery_id}\&#039; AND session = \&#039;#{session}\&#039;&#039;
  
end
&lt;/pre&gt;

(Hope this will work this time ...)</description>
		<content:encoded><![CDATA[<p>Sorry for the double post but seems my Picture model wasn&#8217;t pasted correctly :-p</p>
<pre name="code" class="ruby">
class Picture  true
  file_column :file, :magick =&gt; {
                        :versions =&gt; {  ...  }
    }

  acts_as_list  :scope =&gt; 'gallery_type = \'#{gallery_type}\' AND gallery_id = \'#{gallery_id}\' AND session = \'#{session}\''

end
</pre>
<p>(Hope this will work this time &#8230;)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: seasonfive</title>
		<link>http://donttrustthisguy.com/2006/08/24/rails-whats-the-best-way-to-handle-my-lists/comment-page-1/#comment-4341</link>
		<dc:creator>seasonfive</dc:creator>
		<pubDate>Fri, 04 May 2007 18:32:03 +0000</pubDate>
		<guid isPermaLink="false">http://www.donttrustthisguy.com/2006/08/24/rails-whats-the-best-way-to-handle-my-lists/#comment-4341</guid>
		<description>I had exactly the same problem.
I used polymorphism which is a more generic way to manage than the Album solution (allow each entity to have one or severals picture without database modification) and that works well :

&lt;pre name=&quot;code&quot; class=&quot;ruby&quot;&gt;
class Picture  true  
  file_column :file, :magick =&gt; {
                        :versions =&gt; { ...  }
    }
    
  acts_as_list  :scope =&gt; &#039;gallery_type = \&#039;#{gallery_type}\&#039; AND gallery_id = \&#039;#{gallery_id}\&#039;&#039;  
end

Then in the Content model :

class Content  :gallery 
  ...
end

and in the Car model :

class Car  :gallery
  ...
end
&lt;/pre&gt;

Hope this could help.</description>
		<content:encoded><![CDATA[<p>I had exactly the same problem.<br />
I used polymorphism which is a more generic way to manage than the Album solution (allow each entity to have one or severals picture without database modification) and that works well :</p>
<pre name="code" class="ruby">
class Picture  true
  file_column :file, :magick =&gt; {
                        :versions =&gt; { ...  }
    }

  acts_as_list  :scope =&gt; 'gallery_type = \'#{gallery_type}\' AND gallery_id = \'#{gallery_id}\''
end

Then in the Content model :

class Content  :gallery
  ...
end

and in the Car model :

class Car  :gallery
  ...
end
</pre>
<p>Hope this could help.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bogdan</title>
		<link>http://donttrustthisguy.com/2006/08/24/rails-whats-the-best-way-to-handle-my-lists/comment-page-1/#comment-945</link>
		<dc:creator>Bogdan</dc:creator>
		<pubDate>Thu, 24 Aug 2006 23:00:30 +0000</pubDate>
		<guid isPermaLink="false">http://www.donttrustthisguy.com/2006/08/24/rails-whats-the-best-way-to-handle-my-lists/#comment-945</guid>
		<description>Nice solution Josh. Definitely more simplistic, more like CRUD.

(Sorry Josh, for the incomplete code, but it seems that the comment is somehow &quot;escaped&quot;)</description>
		<content:encoded><![CDATA[<p>Nice solution Josh. Definitely more simplistic, more like CRUD.</p>
<p>(Sorry Josh, for the incomplete code, but it seems that the comment is somehow &#8220;escaped&#8221;)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Josh Knowles</title>
		<link>http://donttrustthisguy.com/2006/08/24/rails-whats-the-best-way-to-handle-my-lists/comment-page-1/#comment-944</link>
		<dc:creator>Josh Knowles</dc:creator>
		<pubDate>Thu, 24 Aug 2006 20:05:42 +0000</pubDate>
		<guid isPermaLink="false">http://www.donttrustthisguy.com/2006/08/24/rails-whats-the-best-way-to-handle-my-lists/#comment-944</guid>
		<description>While I like have the more explicit Domain Model myself, Bogdan&#039;s solution is correct and may actually be simplier if you don&#039;t need the concept of an Album object.  See http://wiki.rubyonrails.org/rails/pages/SimplePolymorphicAssociation for some explanation of what a Polymorphic Association is.

You don&#039;t even need the fancy scope that he is using, you can just get away with doing :scope =&gt; &#039;addressable_id&#039;

Josh</description>
		<content:encoded><![CDATA[<p>While I like have the more explicit Domain Model myself, Bogdan&#8217;s solution is correct and may actually be simplier if you don&#8217;t need the concept of an Album object.  See <a href="http://wiki.rubyonrails.org/rails/pages/SimplePolymorphicAssociation" rel="nofollow">http://wiki.rubyonrails.org/rails/pages/SimplePolymorphicAssociation</a> for some explanation of what a Polymorphic Association is.</p>
<p>You don&#8217;t even need the fancy scope that he is using, you can just get away with doing :scope =&gt; &#8216;addressable_id&#8217;</p>
<p>Josh</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jim</title>
		<link>http://donttrustthisguy.com/2006/08/24/rails-whats-the-best-way-to-handle-my-lists/comment-page-1/#comment-942</link>
		<dc:creator>Jim</dc:creator>
		<pubDate>Thu, 24 Aug 2006 15:40:24 +0000</pubDate>
		<guid isPermaLink="false">http://www.donttrustthisguy.com/2006/08/24/rails-whats-the-best-way-to-handle-my-lists/#comment-942</guid>
		<description>Thanks Bogdan!  Your response is definitely interesting but I believe Josh&#039;s method is the more &#039;rails&#039; way to solve the situation.</description>
		<content:encoded><![CDATA[<p>Thanks Bogdan!  Your response is definitely interesting but I believe Josh&#8217;s method is the more &#8216;rails&#8217; way to solve the situation.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jim</title>
		<link>http://donttrustthisguy.com/2006/08/24/rails-whats-the-best-way-to-handle-my-lists/comment-page-1/#comment-941</link>
		<dc:creator>Jim</dc:creator>
		<pubDate>Thu, 24 Aug 2006 15:37:49 +0000</pubDate>
		<guid isPermaLink="false">http://www.donttrustthisguy.com/2006/08/24/rails-whats-the-best-way-to-handle-my-lists/#comment-941</guid>
		<description>Hey Josh,
Sorry for the confusion if the comments weren&#039;t showing up!  My comments are all moderated.. my site gets a lot of spam comments like over a dozen a day.  Once you&#039;ve been approved you are free to comment from that point onward.</description>
		<content:encoded><![CDATA[<p>Hey Josh,<br />
Sorry for the confusion if the comments weren&#8217;t showing up!  My comments are all moderated.. my site gets a lot of spam comments like over a dozen a day.  Once you&#8217;ve been approved you are free to comment from that point onward.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bogdan</title>
		<link>http://donttrustthisguy.com/2006/08/24/rails-whats-the-best-way-to-handle-my-lists/comment-page-1/#comment-938</link>
		<dc:creator>Bogdan</dc:creator>
		<pubDate>Thu, 24 Aug 2006 11:31:07 +0000</pubDate>
		<guid isPermaLink="false">http://www.donttrustthisguy.com/2006/08/24/rails-whats-the-best-way-to-handle-my-lists/#comment-938</guid>
		<description>With polymorphic associations..

&lt;pre name=&quot;code&quot; class=&quot;ruby&quot;&gt;
class Project  :addressable
end

class Service  :addressable
end

class Image  true
    acts_as_list :scope =&gt; 
       &#039;(addressable_id = #{addressable_id} AND addressable_type = &quot;Project&quot;) OR (addressable_id = #{addressable_id} AND addressable_type = &quot;Service&quot;)&#039;
end
&lt;/pre&gt;

It is based on polymorphic relationships and this excerpt from the documentation: it&#039;s also possible to give it an entire string that is interpolated if you need a tighter scope than just a foreign key. Example: acts_as_list :scope =&gt; @todo_list_id = #{todo_list_id} AND completed = &quot;&quot;.

Hope it&#039;s useful. Haven&#039;t tested it though.</description>
		<content:encoded><![CDATA[<p>With polymorphic associations..</p>
<pre name="code" class="ruby">
class Project  :addressable
end

class Service  :addressable
end

class Image  true
    acts_as_list :scope =&gt;
       '(addressable_id = #{addressable_id} AND addressable_type = "Project") OR (addressable_id = #{addressable_id} AND addressable_type = "Service")'
end
</pre>
<p>It is based on polymorphic relationships and this excerpt from the documentation: it&#8217;s also possible to give it an entire string that is interpolated if you need a tighter scope than just a foreign key. Example: acts_as_list :scope =&gt; @todo_list_id = #{todo_list_id} AND completed = &#8220;&#8221;.</p>
<p>Hope it&#8217;s useful. Haven&#8217;t tested it though.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Josh Knowles</title>
		<link>http://donttrustthisguy.com/2006/08/24/rails-whats-the-best-way-to-handle-my-lists/comment-page-1/#comment-937</link>
		<dc:creator>Josh Knowles</dc:creator>
		<pubDate>Thu, 24 Aug 2006 10:00:39 +0000</pubDate>
		<guid isPermaLink="false">http://www.donttrustthisguy.com/2006/08/24/rails-whats-the-best-way-to-handle-my-lists/#comment-937</guid>
		<description>(note have attempted to add comment couple times but it isn&#039;t displaying all the code... too tired to figure out so I butchered it a bit trying to make it submit correctly, you should still get the general idea)

It&#039;s late, heading to bed, figured I&#039;d try and point you in right direction, not sure if this will make sense or work

What if we change your domain model a tad... Instead of a Photo belonging to both Project or Service what if it belonged to an Album.  You could then have a Project/Service belong_to an album (we use belong_to here so that the foreign key gets placed on the project table as opposed to having to have a project_id and service_id on each album).  You then add an has_many :through to get direct access to the Photos.

Example (note writing from memory check for typos/syntax errors):

&lt;pre name=&quot;code&quot; class=&quot;ruby&quot;&gt;
class Photo 
  belongs_to :album
  acts_as_list :scope =&gt; :album
end

class Album
  has_many :photos
end

class Project
  belongs_to :album
  has_many :photos, :through =&gt; :album
end

class Service
  belongs_to :album
  has_many :photos, :through =&gt; :album
end
&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>(note have attempted to add comment couple times but it isn&#8217;t displaying all the code&#8230; too tired to figure out so I butchered it a bit trying to make it submit correctly, you should still get the general idea)</p>
<p>It&#8217;s late, heading to bed, figured I&#8217;d try and point you in right direction, not sure if this will make sense or work</p>
<p>What if we change your domain model a tad&#8230; Instead of a Photo belonging to both Project or Service what if it belonged to an Album.  You could then have a Project/Service belong_to an album (we use belong_to here so that the foreign key gets placed on the project table as opposed to having to have a project_id and service_id on each album).  You then add an has_many :through to get direct access to the Photos.</p>
<p>Example (note writing from memory check for typos/syntax errors):</p>
<pre name="code" class="ruby">
class Photo
  belongs_to :album
  acts_as_list :scope =&gt; :album
end

class Album
  has_many :photos
end

class Project
  belongs_to :album
  has_many :photos, :through =&gt; :album
end

class Service
  belongs_to :album
  has_many :photos, :through =&gt; :album
end
</pre>
]]></content:encoded>
	</item>
</channel>
</rss>
