<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Rails on the Run &#187; attachment_fu</title>
	<atom:link href="http://railsontherun.com/tag/attachment_fu/feed/" rel="self" type="application/rss+xml" />
	<link>http://railsontherun.com</link>
	<description>Rails experiments by Matt Aimonetti</description>
	<lastBuildDate>Tue, 23 Feb 2010 07:28:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
		<item>
		<title>Attachment_fu updated!</title>
		<link>http://railsontherun.com/2007/11/28/attachment_fu-updated/</link>
		<comments>http://railsontherun.com/2007/11/28/attachment_fu-updated/#comments</comments>
		<pubDate>Wed, 28 Nov 2007 08:26:00 +0000</pubDate>
		<dc:creator>Matt Aimonetti</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[attachment_fu]]></category>
		<category><![CDATA[imagescience]]></category>
		<category><![CDATA[minimagick]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[rmagick]]></category>
		<category><![CDATA[update]]></category>

		<guid isPermaLink="false">http://railsontherun.com/2007/11/28/attachment_fu-updated</guid>
		<description><![CDATA[I recently bugged Rick Olson so much about attachment_fu that he gave me SVN access to fix few bugs. Rick being really busy with ActiveReload he didn&#8217;t spend too much time maintaining attachment_fu. On my side of things, I&#8217;ve been using attachment_fu on a lot of projects and I&#8217;ve been fixing bugs and adding new [...]]]></description>
			<content:encoded><![CDATA[<p>I recently bugged <a href="http://techno-weenie.net/">Rick Olson</a> so much about <a href="http://svn.techno-weenie.net/projects/plugins/attachment_fu/">attachment_fu</a> that he gave me SVN access to fix few bugs.</p>
<p>Rick being really busy with <a href="http://activereload.net/">ActiveReload</a> he didn&#8217;t spend too much time maintaining <a href="http://svn.techno-weenie.net/projects/plugins/attachment_fu/">attachment_fu</a>.</p>
<p>On my side of things, I&#8217;ve been using <a href="http://svn.techno-weenie.net/projects/plugins/attachment_fu/">attachment_fu</a> on a lot of projects and I&#8217;ve been fixing bugs and adding new features.</p>
<p>My first contribution to <a href="http://svn.techno-weenie.net/projects/plugins/attachment_fu/">attachment_fu</a> is a fix for the <a href="http://seattlerb.rubyforge.org/ImageScience.html">ImageScience</a> processor.</p>
<p>Attachment_fu is very flexible and let you use your favorite image processor:</p>
<ul>
<li><a href="http://rmagick.rubyforge.org/">RMagick</a> based on <a href="http://www.imagemagick.org/script/mogrify.php">ImageMagick</a> and <a href="http://www.graphicsmagick.org/">GraphicsMagick</a>(known to leak memory and being a pain to setup)</li>
<li><a href="http://rubyforge.org/projects/mini-magick/">minimagick</a> based on <a href="http://www.imagemagick.org/script/mogrify.php">ImageMagick</a></li>
<li><a href="http://seattlerb.rubyforge.org/ImageScience.html">ImageScience</a> based on <a href="http://sf.net/projects/freeimage">FreeImage</a>. </li>
</ul>
<p>Like many rubyists, I like <a href="http://seattlerb.rubyforge.org/ImageScience.html">ImageScience</a> for its simplicity and efficiency. However, <a href="http://svn.techno-weenie.net/projects/plugins/attachment_fu/">attachment_fu</a> had few problems when being used with <a href="http://seattlerb.rubyforge.org/ImageScience.html">ImageScience</a>.</p>
<ul>
<li>File sizes for thumbnails were not saved correctly in the database. Fixed</li>
<li>Thumbnails based on a gif files were not processed properly. So, this was the big problem. <a href="http://sf.net/projects/freeimage">FreeImage</a> has issues dealing with resizing gif files because of the gif palette limitation (256 colors). to avoid this problem thumbnails of gif files are converted to png. However the thumbnail content type info in the database was not saved properly. That&#8217;s now fixed.</li>
<li>Because of the gif bug reported above, any thumbnail link was broken since it was trying to link to the thumbnail version with a gif extension instead of a png one. Fixed</li>
</ul>
<p>I also fixed a small bug related to <a href="http://www.amazon.com/gp/browse.html?node=16427261">S3 storage</a> and the fact that a_fu had issues loading the config file. (Fixed)</p>
<p>I&#8217;ll also try be able to add some of the S3 features I&#8217;ve been working on. As well as maybe enhancing the validation process. </p>
<p>In the mean time, you might want to read <a href="http://the.railsi.st/2007/11/27/roll-your-own-attachment_fu-validations">this blog post</a> about better validation with attachment_fu.</p>
<p>If you are heavily using attachment_fu or starting using it and think that a google group would be great idea, please let me know in the comment and I&#8217;ll try to convince Technoweenie that we need to set that up <img src='http://railsontherun.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Ooohh I almost forgot, if you fixed some bugs you found while using a<em>fu, please contact me so we can get a</em>fu bug free.</p>
]]></content:encoded>
			<wfw:commentRss>http://railsontherun.com/2007/11/28/attachment_fu-updated/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
		<item>
		<title>attachment_fu + s3 + railroad tip</title>
		<link>http://railsontherun.com/2007/07/23/attachment_fu-s3-railroad-tip/</link>
		<comments>http://railsontherun.com/2007/07/23/attachment_fu-s3-railroad-tip/#comments</comments>
		<pubDate>Mon, 23 Jul 2007 03:47:00 +0000</pubDate>
		<dc:creator>Matt Aimonetti</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[attachment_fu]]></category>
		<category><![CDATA[aws]]></category>
		<category><![CDATA[diagram]]></category>
		<category><![CDATA[graphviz]]></category>
		<category><![CDATA[railsroad]]></category>
		<category><![CDATA[s3]]></category>
		<category><![CDATA[tip]]></category>

		<guid isPermaLink="false">http://railsontherun.com/2007/07/23/attachment_fu-s3-railroad-tip</guid>
		<description><![CDATA[Here is another type for attachment_fu users. This evening I wanted to try Railroad to generate one of my app diagram. I alreay wrote my own script generating a .dot file that I usually import in omnigraffle before exporting a pretty version for my clients. The thing is, my script is quite simple and only [...]]]></description>
			<content:encoded><![CDATA[<p>Here is another type for attachment_fu users.</p>
<p>This evening I wanted to try <a href="http://railroad.rubyforge.org/">Railroad</a> to generate one of my app diagram. I alreay wrote my own script generating a .dot file that I usually import in <a href="http://www.omnigroup.com/applications/omnigraffle/">omnigraffle</a> before exporting a pretty version for my clients. The thing is, my script is quite simple and only covers models while <a href="http://railroad.rubyforge.org/">railroad</a> also deals with controllers.</p>
<p>Wanting to check on railroad, after installing the gem I typed </p>
<pre><code> railroad -o models.dot -M
</code></pre>
<p>and here is the <em>&#8216;pretty&#8217;</em> error message I got.</p>
<p><img src="http://farm2.static.flickr.com/1209/874252844_25e869205e_o.jpg" alt="railroad error msg"/></p>
<p>No worries, Technoweenie didn&#8217;t mess up, it&#8217;s just that I use s3 for storage and his great plugin checks on the environment to load the proper credentials. Since railroad doesn&#8217;t care about the environment, RAILS_ENV isn&#8217;t set and my model diagram isn&#8217;t generated.</p>
<p>To fix this issue, simply type:</p>
<pre><code>$ railroad -o models.dot -M RAILS_ENV='development'
</code></pre>
]]></content:encoded>
			<wfw:commentRss>http://railsontherun.com/2007/07/23/attachment_fu-s3-railroad-tip/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>attachment_fu, Flash and to_xml tips</title>
		<link>http://railsontherun.com/2007/07/21/attachment_fu-flash-and-to_xml-tips/</link>
		<comments>http://railsontherun.com/2007/07/21/attachment_fu-flash-and-to_xml-tips/#comments</comments>
		<pubDate>Sat, 21 Jul 2007 03:30:00 +0000</pubDate>
		<dc:creator>Matt Aimonetti</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[attachment]]></category>
		<category><![CDATA[attachment_fu]]></category>
		<category><![CDATA[edge]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[to_xml]]></category>
		<category><![CDATA[upload]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://railsontherun.com/2007/07/21/attachment_fu-flash-and-to_xml-tips</guid>
		<description><![CDATA[I recently had to deal with an interesting challenge. I had to write a simple interface between a rails app and a Flash application. Nothing hard and if you browse the archives, you&#8217;ll find examples and tutorials on how to create a REST interface to communicate between Rails and Flash. The thing was that this [...]]]></description>
			<content:encoded><![CDATA[<p>I recently had to deal with an interesting challenge. I had to write a simple interface between a rails app and a Flash application. Nothing hard and if you browse the archives, you&#8217;ll find examples and tutorials on how to create a REST interface to communicate between Rails and Flash.</p>
<p>The thing was that this time I had to interface with a model using <a href="http://svn.techno-weenie.net/projects/plugins/attachment_fu/">attachment<em>fu</a>. I&#8217;m a great fan of a</em>fu and it&#8217;s definitely the best way of dealing with uploads. </p>
<p>My model looked more or less like that:</p>
<pre><code>class Photo &lt; ActiveRecord::Base

belongs_to :user

  has_attachment(
    :content_type =&gt; :image,
    :storage =&gt; :file_system,
    :max_size =&gt; 10.megabytes,
    :resize_to =&gt; '640x480&gt;',
    :thumbnails =&gt; { :thumb =&gt; '100x100&gt;',
                              :preview =&gt; '300x200&gt;',
                     }
  )
  validates_as_attachment
  # read more about validates_existence_of http://blog.hasmanythrough.com/2007/7/14/validate-your-existence
  validates_existence_of :user
end
</code></pre>
<p>My show action in my photo controller could have looked a bit like that:</p>
<pre><code>respond_to do |format|
  format.html # show.html.erb
  format.xml  { render <img src='http://railsontherun.com/wp-includes/images/smilies/icon_mad.gif' alt=':x' class='wp-smiley' /> ml =&gt; @photo }
end
</code></pre>
<p>That&#8217;s great, the problem is that we are displaying a lot of information that our Flash client doesn&#8217;t need to see, actually we are exposing a lot of information nobody should ever see and we are not displaying what we should. On top of being a waste of bandwidth and giving too much work to the client, we are not actually providing the user with the details of the thumbnail.</p>
<p>The first thing to do would be not to display some of the object attributes, the to_xml method lets you do that. </p>
<p>Note that in Edge, Rails will automatically try to convert your object using to<em>xml, you don&#8217;t even need to mention it. However in our case, we want to use some _advanced</em> features offered by to_xml, and here is how our code should look like:  </p>
<pre><code>format.xml do
  render <img src='http://railsontherun.com/wp-includes/images/smilies/icon_mad.gif' alt=':x' class='wp-smiley' /> ml =&gt; @photo.to_xml( :except =&gt; [ :id, :filename, :updated_at, :user_id, :height, :width], :skip_types =&gt; true )
end
</code></pre>
<p>What I just did is very simple, we rendered our object as an xml object but we didn&#8217;t convert few attributes, :id, :filename, :updated<em>at, :user</em>id, :height, :width. By default Rails also adds the object type, we don&#8217;t really need that right now, so let&#8217;s skip them.<br/><br />
(The reason why I don&#8217;t want to convert the filename is that I want to provide our Flash client with the photo thumbnail instead of the original picture.)</p>
<p>As far as I know, to_xml doesn&#8217;t let you create new attributes. (if I have some time, I&#8217;ll submit a patch to get that added).</p>
<p>What we are trying to do is to display the avatar of a user. We found the photo record using @user.photo but that&#8217;s the original photo and we want to provide Flash with the avatar info, not the original.</p>
<p>What we need to do is to simply add a new attribute called avatar:</p>
<pre><code>format.xml do
  @photo[:avatar] = @photo.public_filename(:thumb)
  render <img src='http://railsontherun.com/wp-includes/images/smilies/icon_mad.gif' alt=':x' class='wp-smiley' /> ml =&gt; @photo.to_xml( :except =&gt; [ :id, :filename, :updated_at, :user_id, :height, :width], :skip_types =&gt; true )
end
</code></pre>
<p>Simple enough, but it took me a little while to figure it out <img src='http://railsontherun.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>Voila, we now have a clean, trimmed and safe XML returned object that you can be consumed by our Flash client. Ohh, and we added a new attribute that the original object didn&#8217;t have <img src='http://railsontherun.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://railsontherun.com/2007/07/21/attachment_fu-flash-and-to_xml-tips/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>new rails plugin: mimetype_fu</title>
		<link>http://railsontherun.com/2007/06/14/new-rails-plugin-mimetype_fu/</link>
		<comments>http://railsontherun.com/2007/06/14/new-rails-plugin-mimetype_fu/#comments</comments>
		<pubDate>Thu, 14 Jun 2007 04:45:00 +0000</pubDate>
		<dc:creator>Matt Aimonetti</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[attachment_fu]]></category>
		<category><![CDATA[content type]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[mime]]></category>
		<category><![CDATA[mime type\']]></category>
		<category><![CDATA[mimetype_fu]]></category>
		<category><![CDATA[plugins]]></category>
		<category><![CDATA[upload]]></category>

		<guid isPermaLink="false">http://railsontherun.com/2007/06/14/new-rails-plugin-mimetype_fu</guid>
		<description><![CDATA[mimetype_fu/ is a new plugin I just wrote. It&#8217;s simple and it can be really useful if you need to get the mime type of a file already on your server. During one of my project, I add to migrate old assets from a legacy system to a new Rails app. The new app uses [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://code.google.com/p/mimetype-fu/">mimetype_fu/</a> is a new plugin I just wrote. It&#8217;s simple and it can be really useful if you need to get the mime type of a file already on your server.</p>
<p>During one of my project, I add to migrate old assets from a legacy system to a new Rails app. The new app uses <a href="http://svn.techno-weenie.net/projects/plugins/attachment_fu/">attachment fu</a> and even though techno weenie did an amazing job, attachment<em>fu validation is based on the content type. A</em>fu gets the content type coming from the CGI query. </p>
<p>Unit test has a helper faking this process but in real life, if you use a Flash uploader (Flash doesn&#8217;t give you the proper mime type/content type) or if you want to migrate files, the attachment_fu validation won&#8217;t work for you.</p>
<p>The solution is simple: <a href="http://code.google.com/p/mimetype-fu/">mimetype_fu/</a></p>
<p><a href="http://code.google.com/p/mimetype-fu/">mimetype_fu/</a> extends the File class and is really easy to use:</p>
<pre><code>File.mime_type?(@file)
</code></pre>
<p>Check it out <a href="http://code.google.com/p/mimetype-fu/">http://code.google.com/p/mimetype-fu/</a></p>
<p>Expect a post showing how a ninja would use the mimetype<em>fu / attachment</em>fu combo <img src='http://railsontherun.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://railsontherun.com/2007/06/14/new-rails-plugin-mimetype_fu/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

