<?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>James Wilding&#039;s Weblog &#187; paperclip</title>
	<atom:link href="http://jameswilding.net/tag/paperclip/feed/" rel="self" type="application/rss+xml" />
	<link>http://jameswilding.net</link>
	<description>Buddhist businessman, freelance web developer</description>
	<lastBuildDate>Sun, 05 Sep 2010 09:38:56 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Paperclip on Rails 3</title>
		<link>http://jameswilding.net/feeder/?FeederAction=clicked&amp;feed=Posts+%28RSS2%29&amp;seed=http%3A%2F%2Fjameswilding.net%2F2010%2F07%2F24%2Fpaperclip-rails-3%2F&amp;seed_title=Paperclip+on+Rails+3</link>
		<comments>http://jameswilding.net/2010/07/24/paperclip-rails-3/#comments</comments>
		<pubDate>Sat, 24 Jul 2010 10:56:39 +0000</pubDate>
		<dc:creator>James</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[paperclip]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[rails3]]></category>

		<guid isPermaLink="false">http://jameswilding.net/?p=695</guid>
		<description><![CDATA[You want to run Rails 3. You want to use the excellent Paperclip plugin to mess with your attached files. Not a problem. It Just Works Paperclip on Rails 3 now just works. Back in February 2010, I wrote about how to use Paperclip on an early beta release of Rails 3 &#8212; back then, [...]]]></description>
			<content:encoded><![CDATA[<p>You want to run Rails 3. You want to use <a href="http://github.com/thoughtbot/paperclip">the excellent Paperclip plugin</a> to mess with your attached files. Not a problem.</p>
<h3>It Just Works</h3>
<p>Paperclip on Rails 3 now just works.</p>
<p><a href="http://jameswilding.net/2010/02/07/paperclip-on-rails-3-beta/">Back in February 2010</a>, I wrote about how to use Paperclip on an early beta release of Rails 3 &#8212; back then, a few small hacks were required to get Paperclip running. Now Rails 3 is at beta 4, and it&#8217;s safe to assume that we&#8217;re as close as we can be to an official Rails release &#8212; minus a few last minute tweaks, of course &#8212; and both the framework itself and the Paperclip plugin are more stable and more compatible. The good news, then, is that it&#8217;s very easy to use the Rails 3 and Paperclip together.</p>
<h3>How To Use Paperclip With Rails 3</h3>
<p>These instructions are good for Rails 3 beta 4, and Paperclip <a href="http://github.com/thoughtbot/paperclip/commit/9223a917a821731986603e89a9b2e4d1a4fdd68a">9223a917</a>. They&#8217;ll probably work on other versions of Rails and Paperclip, too.</p>
<ol>
<li>Install Rails 3</li>
<li>Create a new Rails app</li>
<li>Install Paperclip</li>
<li>Create a model</li>
<li>Create a controller and views</li>
<li>Define your routes</li>
</ol>
<p>You can find the important files (controller, model, views, and routes) in <a href="http://gist.github.com/488579">this gist</a>, and the full application code is <a href="http://github.com/jameswilding/paperclip_example">available on Github</a>.</p>
<h4>Install Rails 3</h4>
<p>Install the latest prerelease of Rails with the following:</p>
<pre>$ gem install rails --pre</pre>
<h4>Create a new Rails app</h4>
<p>The command for creating Rails apps has changed in Rails 3. In the bright new future, everything is done using &#8220;rails&#8221; <a class="simple-footnote" title="I&#8217;ve found that, on Mac OSX 10.6, I have to use &#8220;/usr/bin/rails&#8221; (that&#8217;s where my Rails binary lives) instead of &#8220;rails&#8221;. No doubt that will be fixed soon." id="return-note-695-1" href="#note-695-1"><sup>1</sup></a>:</p>
<pre>$ rails new paperclip_example</pre>
<h4>Install Paperclip</h4>
<p>Paperclip&#8217;s master branch is now good to go with Rails 3. Install from Github thus:</p>
<pre>$ rails plugin install git://github.com/thoughtbot/paperclip.git</pre>
<h4>Create a model</h4>
<p>In order to work with Paperclip, your model needs a few special database columns. In this case, I&#8217;m creating a User class which will have an attached avatar image.</p>
<pre>$ rails generate model User \
avatar_file_name:string \
avatar_content_type:string \
avatar_file_size:integer \
avatar_updated_at:datetime
$ rake db:migrate</pre>
<p>I use Paperclip&#8217;s has_attached_file method to define my avatar attachment:</p>
<pre>class User &lt; ActiveRecord::Base
  has_attached_file :avatar, :styles =&gt; {
    :thumb =&gt; '50x'
  }
end</pre>
<h4>Create a controller and views</h4>
<p>I&#8217;m setting up a simple UsersController with index, new, and create actions (and corresponding routes). You&#8217;ll probably want to go further, but if all you&#8217;re interested in is proof-of-concept then this is enough.</p>
<pre>$ rails generate controller Users</pre>
<p>See <a href="http://gist.github.com/488579">this gist</a> for the code in my UsersController, and the HTML in my views.</p>
<h4>Define your routes</h4>
<p>In config/routes.rb:</p>
<pre>PaperclipExample::Application.routes.draw do |map|
  resources :users, :only =&gt; [:index, :new, :create]
  root :to =&gt; 'users#index'
end</pre>
<p>Lastly, if you&#8217;re mapping your app&#8217;s root to a controller, remember to delete public/index.html.</p>
<h3>And You&#8217;re Done</h3>
<p>That&#8217;s really all there is to it. Use rails server to start your app and view the results. Did it work for you?</p>
<div class="simple-footnotes"><p class="notes">Notes:</p><ol><li id="note-695-1">I&#8217;ve found that, on Mac OSX 10.6, I have to use &#8220;/usr/bin/rails&#8221; (that&#8217;s where my Rails binary lives) instead of &#8220;rails&#8221;. No doubt that will be fixed soon. <a href="#return-note-695-1">&#8617;</a></li></ol></div>]]></content:encoded>
			<wfw:commentRss>http://jameswilding.net/2010/07/24/paperclip-rails-3/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Paperclip on Rails 3 Beta</title>
		<link>http://jameswilding.net/feeder/?FeederAction=clicked&amp;feed=Posts+%28RSS2%29&amp;seed=http%3A%2F%2Fjameswilding.net%2F2010%2F02%2F07%2Fpaperclip-on-rails-3-beta%2F&amp;seed_title=Paperclip+on+Rails+3+Beta</link>
		<comments>http://jameswilding.net/2010/02/07/paperclip-on-rails-3-beta/#comments</comments>
		<pubDate>Sun, 07 Feb 2010 19:30:43 +0000</pubDate>
		<dc:creator>James</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[paperclip]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[rails3]]></category>

		<guid isPermaLink="false">http://jameswilding.net/?p=504</guid>
		<description><![CDATA[More fun with Rails 3 beta.]]></description>
			<content:encoded><![CDATA[<p class="update"><strong>Update:</strong> you should <a href="http://jameswilding.net/2010/07/24/paperclip-rails-3/">read this more recent article</a> for an explanation of how to use Paperclip with the latest beta release of Rails 3.</p>
<p>I got Paperclip working on Rails 3 today. Here&#8217;s how.</p>
<p>First, I found (by accident) <a href="http://github.com/thoughtbot/paperclip/tree/rails3">a branch in the Paperclip repository</a> on Github called &#8220;Rails 3&#8243;. Call me crazy but I thought that might be worth a try.</p>
<p>Normally you&#8217;d install Rails 3 plugins using rails plugin install, but in this case I used git submodule:</p>
<p><script src="http://gist.github.com/298015.js?file=gistfile1.txt"></script></p>
<p>These two commands checkout the rails3 branch of Paperclip into vendor/plugins/paperclip, as a Git submodule. If you don&#8217;t understand Git submodules, you can <a href="http://book.git-scm.com/5_submodules.html">read about them here</a>.</p>
<p>I also found that Paperclip wasn&#8217;t properly handling image styles; the &#8216;Paperclip&#8217; section of <a href="http://jameswilding.net/2010/02/07/working-with-rails-3/">this post</a> explains how I fixed this (a word of warning: it&#8217;s a simple one-line edit which solved my problem but is untested with regard to the rest of Paperclip).</p>
<p>As always, feel free to post questions or feedback in the comments. Good luck!</p>
]]></content:encoded>
			<wfw:commentRss>http://jameswilding.net/2010/02/07/paperclip-on-rails-3-beta/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
