<?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&#8217; attachment_fu, :thumbnail_class and you</title>
	<atom:link href="http://blog.layer2.org/2007/11/19/rails-attachment_fu-thumbnail_class-and-you/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.layer2.org/2007/11/19/rails-attachment_fu-thumbnail_class-and-you/</link>
	<description>A technical blog</description>
	<lastBuildDate>Wed, 24 Mar 2010 15:18:55 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Ryan Heath</title>
		<link>http://blog.layer2.org/2007/11/19/rails-attachment_fu-thumbnail_class-and-you/comment-page-1/#comment-233</link>
		<dc:creator>Ryan Heath</dc:creator>
		<pubDate>Tue, 10 Nov 2009 17:26:27 +0000</pubDate>
		<guid isPermaLink="false">http://blog.layer2.org/2007/11/19/rails-attachment_fu-thumbnail_class-and-you/#comment-233</guid>
		<description>That&#039;s definitely one approach, but you can also pass a condition to the validation. Something like this:


validates_presence_of :name, :description
  :if =&gt; Proc.new { &#124;record&#124; record.parent_id.blank? }


I realize this post is old now, but I thought I&#039;d comment anyway :-)</description>
		<content:encoded><![CDATA[<p>That&#8217;s definitely one approach, but you can also pass a condition to the validation. Something like this:</p>
<p>validates_presence_of :name, :description<br />
  :if =&gt; Proc.new { |record| record.parent_id.blank? }</p>
<p>I realize this post is old now, but I thought I&#8217;d comment anyway <img src='http://blog.layer2.org/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Prachi</title>
		<link>http://blog.layer2.org/2007/11/19/rails-attachment_fu-thumbnail_class-and-you/comment-page-1/#comment-212</link>
		<dc:creator>Prachi</dc:creator>
		<pubDate>Tue, 15 Sep 2009 13:21:37 +0000</pubDate>
		<guid isPermaLink="false">http://blog.layer2.org/2007/11/19/rails-attachment_fu-thumbnail_class-and-you/#comment-212</guid>
		<description>Thanks a lot! This worked :)</description>
		<content:encoded><![CDATA[<p>Thanks a lot! This worked <img src='http://blog.layer2.org/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kevin Nolan</title>
		<link>http://blog.layer2.org/2007/11/19/rails-attachment_fu-thumbnail_class-and-you/comment-page-1/#comment-188</link>
		<dc:creator>Kevin Nolan</dc:creator>
		<pubDate>Sun, 28 Sep 2008 19:24:43 +0000</pubDate>
		<guid isPermaLink="false">http://blog.layer2.org/2007/11/19/rails-attachment_fu-thumbnail_class-and-you/#comment-188</guid>
		<description>Perhaps missing something, but why not subclass Thumbnail from Photo? The only consequence of this that I see is that you have both photos and thumbnails in the same table, which is the default case when you don&#039;t supply a thumbnail class in the first place.</description>
		<content:encoded><![CDATA[<p>Perhaps missing something, but why not subclass Thumbnail from Photo? The only consequence of this that I see is that you have both photos and thumbnails in the same table, which is the default case when you don&#8217;t supply a thumbnail class in the first place.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Liam</title>
		<link>http://blog.layer2.org/2007/11/19/rails-attachment_fu-thumbnail_class-and-you/comment-page-1/#comment-169</link>
		<dc:creator>Liam</dc:creator>
		<pubDate>Thu, 10 Apr 2008 21:45:22 +0000</pubDate>
		<guid isPermaLink="false">http://blog.layer2.org/2007/11/19/rails-attachment_fu-thumbnail_class-and-you/#comment-169</guid>
		<description>Thanks for your quick response.

In my Thumbnail model I included belongs_to :person and in my Person model I had both has_one :photo and has_one :thumbnail. I got ride of belongs_to :person (in Thumbnail model) and got rid of has_one :thumbnail (in Person model) restarted the server and your example worked.

Given that I only have 1 Thumbnail per Photo I only need to do:
p.photo.thumbnails</description>
		<content:encoded><![CDATA[<p>Thanks for your quick response.</p>
<p>In my Thumbnail model I included belongs_to :person and in my Person model I had both has_one :photo and has_one :thumbnail. I got ride of belongs_to :person (in Thumbnail model) and got rid of has_one :thumbnail (in Person model) restarted the server and your example worked.</p>
<p>Given that I only have 1 Thumbnail per Photo I only need to do:<br />
p.photo.thumbnails</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: solipsistic</title>
		<link>http://blog.layer2.org/2007/11/19/rails-attachment_fu-thumbnail_class-and-you/comment-page-1/#comment-168</link>
		<dc:creator>solipsistic</dc:creator>
		<pubDate>Thu, 10 Apr 2008 03:31:59 +0000</pubDate>
		<guid isPermaLink="false">http://blog.layer2.org/2007/11/19/rails-attachment_fu-thumbnail_class-and-you/#comment-168</guid>
		<description>@Liam

I&#039;m not sure why your photos aren&#039;t showing thumbnails. Mine work fine. Maybe you could describe exactly what you mean by &quot;does not work&quot; ? Error? Empty set?

I do the same thing you&#039;re trying to accomplish with your Person model, except mine is called User. I do something like

&lt;pre&gt;
u = User.find 1
u.photos.first.thumbnails.first
&lt;/pre&gt;

using 

&lt;pre&gt;
class User
  has_many :photos
end

class Photo
  belongs_to :user
end
&lt;/pre&gt;

to give me the thumbnail. It sounds like you only have one Photo per Person, so you could probably do something like

&lt;pre&gt;
p = Person.find 1
p.photo.thumbnails.first
&lt;/pre&gt;

Do a 

&lt;pre&gt;
class Person
  def thumbnail
    thumbnails.first
  end
end
&lt;/pre&gt;

to make your life a bit easier and allow

&lt;pre&gt;
p = Person.find 1
p.photo.thumbnail
&lt;/pre&gt;

This is, of course, assuming you want only one Thumbnail per Photo.</description>
		<content:encoded><![CDATA[<p>@Liam</p>
<p>I&#8217;m not sure why your photos aren&#8217;t showing thumbnails. Mine work fine. Maybe you could describe exactly what you mean by &#8220;does not work&#8221; ? Error? Empty set?</p>
<p>I do the same thing you&#8217;re trying to accomplish with your Person model, except mine is called User. I do something like</p>
<pre>
u = User.find 1
u.photos.first.thumbnails.first
</pre>
<p>using </p>
<pre>
class User
  has_many :photos
end

class Photo
  belongs_to :user
end
</pre>
<p>to give me the thumbnail. It sounds like you only have one Photo per Person, so you could probably do something like</p>
<pre>
p = Person.find 1
p.photo.thumbnails.first
</pre>
<p>Do a </p>
<pre>
class Person
  def thumbnail
    thumbnails.first
  end
end
</pre>
<p>to make your life a bit easier and allow</p>
<pre>
p = Person.find 1
p.photo.thumbnail
</pre>
<p>This is, of course, assuming you want only one Thumbnail per Photo.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Liam</title>
		<link>http://blog.layer2.org/2007/11/19/rails-attachment_fu-thumbnail_class-and-you/comment-page-1/#comment-167</link>
		<dc:creator>Liam</dc:creator>
		<pubDate>Thu, 10 Apr 2008 02:24:46 +0000</pubDate>
		<guid isPermaLink="false">http://blog.layer2.org/2007/11/19/rails-attachment_fu-thumbnail_class-and-you/#comment-167</guid>
		<description>Thanks for the quick tutorial!

In the last lines you show off the nice relationship between photo and thumbnails. So for a given thumbnail you can find its photo. I can&#039;t seem to get it work as easily the other way arround: for a given photo I&#039;d like to find its thumbnail.

for instance: 
p = Photo.find :all
p.first.thumbnails

does not work!

As an added layer of complexity, my photos belong_to :person. So for a given person I can find their photo. However I can&#039;t figure out to include the person_id (which connects a given photo with a person) into each thumbnail database entry (to connect a given thumbnail with a person).

Any suggestions?</description>
		<content:encoded><![CDATA[<p>Thanks for the quick tutorial!</p>
<p>In the last lines you show off the nice relationship between photo and thumbnails. So for a given thumbnail you can find its photo. I can&#8217;t seem to get it work as easily the other way arround: for a given photo I&#8217;d like to find its thumbnail.</p>
<p>for instance:<br />
p = Photo.find :all<br />
p.first.thumbnails</p>
<p>does not work!</p>
<p>As an added layer of complexity, my photos belong_to :person. So for a given person I can find their photo. However I can&#8217;t figure out to include the person_id (which connects a given photo with a person) into each thumbnail database entry (to connect a given thumbnail with a person).</p>
<p>Any suggestions?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: fulvio</title>
		<link>http://blog.layer2.org/2007/11/19/rails-attachment_fu-thumbnail_class-and-you/comment-page-1/#comment-139</link>
		<dc:creator>fulvio</dc:creator>
		<pubDate>Sun, 03 Feb 2008 05:17:25 +0000</pubDate>
		<guid isPermaLink="false">http://blog.layer2.org/2007/11/19/rails-attachment_fu-thumbnail_class-and-you/#comment-139</guid>
		<description>I noticed that this works for any type of custom defined thumbnail (ie. :thumbnails { :any =&gt; &quot;28x28&gt;&quot; }).

This is exactly what I&#039;ve been after for a while.

Thanks a million!</description>
		<content:encoded><![CDATA[<p>I noticed that this works for any type of custom defined thumbnail (ie. :thumbnails { :any =&gt; &#8220;28&#215;28&gt;&#8221; }).</p>
<p>This is exactly what I&#8217;ve been after for a while.</p>
<p>Thanks a million!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: solipsistic</title>
		<link>http://blog.layer2.org/2007/11/19/rails-attachment_fu-thumbnail_class-and-you/comment-page-1/#comment-132</link>
		<dc:creator>solipsistic</dc:creator>
		<pubDate>Fri, 11 Jan 2008 02:50:18 +0000</pubDate>
		<guid isPermaLink="false">http://blog.layer2.org/2007/11/19/rails-attachment_fu-thumbnail_class-and-you/#comment-132</guid>
		<description>Yes, yes it should. Fixed.</description>
		<content:encoded><![CDATA[<p>Yes, yes it should. Fixed.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Greg</title>
		<link>http://blog.layer2.org/2007/11/19/rails-attachment_fu-thumbnail_class-and-you/comment-page-1/#comment-131</link>
		<dc:creator>Greg</dc:creator>
		<pubDate>Tue, 08 Jan 2008 18:03:38 +0000</pubDate>
		<guid isPermaLink="false">http://blog.layer2.org/2007/11/19/rails-attachment_fu-thumbnail_class-and-you/#comment-131</guid>
		<description>Shouldn&#039;t your Photo have many :thumbnails and not photos?</description>
		<content:encoded><![CDATA[<p>Shouldn&#8217;t your Photo have many :thumbnails and not photos?</p>
]]></content:encoded>
	</item>
</channel>
</rss>

<!-- Dynamic Page Served (once) in 0.306 seconds -->
