<?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>Tristan Media Blog &#187; Rails</title>
	<atom:link href="http://blog.tristanmedia.com/category/rails/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.tristanmedia.com</link>
	<description>One can never have enough scripting languages: Notes on Perl, PHP, and Ruby</description>
	<lastBuildDate>Sun, 11 Jul 2010 01:10:53 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Validating URLs for non-ActiveRecord objects</title>
		<link>http://blog.tristanmedia.com/2010/07/validating-urls-for-non-activerecord-objects/</link>
		<comments>http://blog.tristanmedia.com/2010/07/validating-urls-for-non-activerecord-objects/#comments</comments>
		<pubDate>Fri, 09 Jul 2010 23:12:10 +0000</pubDate>
		<dc:creator>Barry</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[mongoid]]></category>

		<guid isPermaLink="false">http://blog.tristanmedia.com/?p=107</guid>
		<description><![CDATA[I'm using Mongoid and MongoDB on a new project, so my models are not derived from ActiveModel. On previous projects I just used the validates_url_format_of plugin, but for this project I put the code from the module into an initializer (config/initializers/validation.rb) and used extend. module ValidatesUrlFormatOf IPv4_PART = /\d&#124;&#91;1-9&#93;\d&#124;1\d\d&#124;2&#91;0-4&#93;\d&#124;25&#91;0-5&#93;/ # 0-255 REGEXP = %r&#123; \A [...]]]></description>
			<content:encoded><![CDATA[<p>I'm using <a href="http://mongoid.org/">Mongoid</a> and MongoDB on a new project, so my models are not derived from ActiveModel.  On previous projects I just used the <a href="http://github.com/henrik/validates_url_format_of">validates_url_format_of</a> plugin, but for this project I put the code from the module into an initializer (config/initializers/validation.rb) and used <code>extend</code>.</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">module</span> ValidatesUrlFormatOf
  IPv4_PART = <span style="color:#006600; font-weight:bold;">/</span>\d<span style="color:#006600; font-weight:bold;">|</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">1</span><span style="color:#006600; font-weight:bold;">-</span><span style="color:#006666;">9</span><span style="color:#006600; font-weight:bold;">&#93;</span>\d<span style="color:#006600; font-weight:bold;">|</span><span style="color:#006666;">1</span>\d\d<span style="color:#006600; font-weight:bold;">|</span><span style="color:#006666;">2</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">0</span><span style="color:#006600; font-weight:bold;">-</span><span style="color:#006666;">4</span><span style="color:#006600; font-weight:bold;">&#93;</span>\d<span style="color:#006600; font-weight:bold;">|</span><span style="color:#006666;">25</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">0</span><span style="color:#006600; font-weight:bold;">-</span><span style="color:#006666;">5</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">/</span>  <span style="color:#008000; font-style:italic;"># 0-255</span>
  REGEXP = <span style="color:#006600; font-weight:bold;">%</span>r<span style="color:#006600; font-weight:bold;">&#123;</span>
    \A
    https?:<span style="color:#006600; font-weight:bold;">//</span>                                                    <span style="color:#008000; font-style:italic;"># http:// or https://</span>
    <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#91;</span>^\s:@<span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">+</span>:<span style="color:#006600; font-weight:bold;">&#91;</span>^\s:@<span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">*</span>@<span style="color:#006600; font-weight:bold;">&#41;</span>?                                        <span style="color:#008000; font-style:italic;"># optional username:pw@</span>
    <span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#91;</span>^\W_<span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">+</span>\.<span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">*</span>xn<span style="color:#006600; font-weight:bold;">--</span><span style="color:#006600; font-weight:bold;">&#41;</span>?<span style="color:#006600; font-weight:bold;">&#91;</span>^\W_<span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">+</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006600; font-weight:bold;">-</span>.<span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#91;</span>^\W_<span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">+</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">*</span>\.<span style="color:#006600; font-weight:bold;">&#91;</span>a<span style="color:#006600; font-weight:bold;">-</span>z<span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006666;">2</span>,<span style="color:#006666;">6</span><span style="color:#006600; font-weight:bold;">&#125;</span>\.? <span style="color:#006600; font-weight:bold;">|</span>  <span style="color:#008000; font-style:italic;"># domain (including Punycode/IDN)...</span>
        <span style="color:#008000; font-style:italic;">#{IPv4_PART}(\.#{IPv4_PART}){3} )                        # or IPv4</span>
    <span style="color:#006600; font-weight:bold;">&#40;</span>:\d<span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006666;">1</span>,<span style="color:#006666;">5</span><span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span>?                                                  <span style="color:#008000; font-style:italic;"># optional port</span>
    <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006600; font-weight:bold;">/</span>?<span style="color:#006600; font-weight:bold;">&#93;</span>\S<span style="color:#006600; font-weight:bold;">*</span><span style="color:#006600; font-weight:bold;">&#41;</span>?                                                   <span style="color:#008000; font-style:italic;"># optional /whatever or ?whatever</span>
    \Z
  <span style="color:#006600; font-weight:bold;">&#125;</span>iux
&nbsp;
  DEFAULT_MESSAGE     = <span style="color:#996600;">'does not appear to be a valid URL'</span>
  DEFAULT_MESSAGE_URL = <span style="color:#996600;">'does not appear to be valid'</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> validates_url_format_of<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">*</span>attr_names<span style="color:#006600; font-weight:bold;">&#41;</span>
    options = <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#ff3333; font-weight:bold;">:allow_nil</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">false</span>,
                <span style="color:#ff3333; font-weight:bold;">:allow_blank</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">false</span>,
                <span style="color:#ff3333; font-weight:bold;">:with</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> REGEXP <span style="color:#006600; font-weight:bold;">&#125;</span>
    options = options.<span style="color:#9900CC;">merge</span><span style="color:#006600; font-weight:bold;">&#40;</span>attr_names.<span style="color:#9900CC;">pop</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">if</span> attr_names.<span style="color:#9900CC;">last</span>.<span style="color:#9900CC;">is_a</span>?<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC00FF; font-weight:bold;">Hash</span><span style="color:#006600; font-weight:bold;">&#41;</span>
&nbsp;
    attr_names.<span style="color:#9900CC;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>attr_name<span style="color:#006600; font-weight:bold;">|</span>
      message = attr_name.<span style="color:#9900CC;">to_s</span>.<span style="color:#9900CC;">match</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">/</span><span style="color:#006600; font-weight:bold;">&#40;</span>_<span style="color:#006600; font-weight:bold;">|</span>\b<span style="color:#006600; font-weight:bold;">&#41;</span>URL<span style="color:#006600; font-weight:bold;">&#40;</span>_<span style="color:#006600; font-weight:bold;">|</span>\b<span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">/</span>i<span style="color:#006600; font-weight:bold;">&#41;</span> ? DEFAULT_MESSAGE_URL : DEFAULT_MESSAGE
      validates_format_of<span style="color:#006600; font-weight:bold;">&#40;</span>attr_name, <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#ff3333; font-weight:bold;">:message</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> message <span style="color:#006600; font-weight:bold;">&#125;</span>.<span style="color:#9900CC;">merge</span><span style="color:#006600; font-weight:bold;">&#40;</span>options<span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>Then my model extends that module:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">class</span> Location
  <span style="color:#9966CC; font-weight:bold;">include</span> <span style="color:#6666ff; font-weight:bold;">Mongoid::Document</span>
  <span style="color:#9966CC; font-weight:bold;">include</span> <span style="color:#6666ff; font-weight:bold;">Mongoid::Timestamps</span>
  extend ValidatesUrlFormatOf
&nbsp;
  validates_url_format_of <span style="color:#ff3333; font-weight:bold;">:url</span>, <span style="color:#ff3333; font-weight:bold;">:allow_blank</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">true</span>
...</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://blog.tristanmedia.com/2010/07/validating-urls-for-non-activerecord-objects/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Testing HTTP basic authentication with RSpec 2</title>
		<link>http://blog.tristanmedia.com/2010/07/testing-http-basic-authentication-with-rspec-2/</link>
		<comments>http://blog.tristanmedia.com/2010/07/testing-http-basic-authentication-with-rspec-2/#comments</comments>
		<pubDate>Wed, 07 Jul 2010 02:00:50 +0000</pubDate>
		<dc:creator>Barry</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[rspec]]></category>

		<guid isPermaLink="false">http://blog.tristanmedia.com/?p=97</guid>
		<description><![CDATA[Here's how I test my admin controllers that use HTTP basic authentication using RSpec 2: before&#40;:each&#41; do user = 'test' pw = 'test_pw' request.env&#91;'HTTP_AUTHORIZATION'&#93; = ActionController::HttpAuthentication::Basic.encode_credentials&#40;user,pw&#41; end Actually, that's how I did it when I first tested things, but I've since put it in its own module under spec/support/auth_helper: module AuthHelper # do admin login [...]]]></description>
			<content:encoded><![CDATA[<p>Here's how I test my admin controllers that use HTTP basic authentication using RSpec 2:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">before<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:each</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">do</span>
    user = <span style="color:#996600;">'test'</span>
    pw = <span style="color:#996600;">'test_pw'</span>
    request.<span style="color:#9900CC;">env</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'HTTP_AUTHORIZATION'</span><span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#6666ff; font-weight:bold;">ActionController::HttpAuthentication::Basic</span>.<span style="color:#9900CC;">encode_credentials</span><span style="color:#006600; font-weight:bold;">&#40;</span>user,pw<span style="color:#006600; font-weight:bold;">&#41;</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>Actually, that's how I did it when I first tested things, but I've since put it in its own module under spec/support/auth_helper:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">module</span> AuthHelper
  <span style="color:#008000; font-style:italic;"># do admin login</span>
  <span style="color:#9966CC; font-weight:bold;">def</span> admin_login
    user = <span style="color:#996600;">'test'</span>
    pw = <span style="color:#996600;">'test_pw'</span>
    request.<span style="color:#9900CC;">env</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'HTTP_AUTHORIZATION'</span><span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#6666ff; font-weight:bold;">ActionController::HttpAuthentication::Basic</span>.<span style="color:#9900CC;">encode_credentials</span><span style="color:#006600; font-weight:bold;">&#40;</span>user,pw<span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>  
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>and now my controller spec looks like this:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">describe <span style="color:#6666ff; font-weight:bold;">Admin::LocationsController</span> <span style="color:#9966CC; font-weight:bold;">do</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">include</span> AuthHelper
&nbsp;
  before<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:each</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">do</span>
    admin_login
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  describe <span style="color:#996600;">&quot;GET index&quot;</span> <span style="color:#9966CC; font-weight:bold;">do</span>
    it <span style="color:#996600;">&quot;assigns all locations as @locations&quot;</span> <span style="color:#9966CC; font-weight:bold;">do</span>
      loc = Factory.<span style="color:#9900CC;">create</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:location</span><span style="color:#006600; font-weight:bold;">&#41;</span>
      get <span style="color:#ff3333; font-weight:bold;">:index</span>
      assigns<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:locations</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">should</span> eq<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#91;</span>loc<span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  describe <span style="color:#996600;">&quot;GET show&quot;</span> <span style="color:#9966CC; font-weight:bold;">do</span>
    it <span style="color:#996600;">&quot;assigns the requested location as @location&quot;</span> <span style="color:#9966CC; font-weight:bold;">do</span>
      loc = Factory.<span style="color:#9900CC;">create</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:location</span><span style="color:#006600; font-weight:bold;">&#41;</span>
      get <span style="color:#ff3333; font-weight:bold;">:show</span>, <span style="color:#ff3333; font-weight:bold;">:id</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> loc.<span style="color:#9900CC;">id</span>
      assigns<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:location</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">should</span> === loc
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>  
&nbsp;
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>That "Factory" line comes from my use of <a href="http://github.com/thoughtbot/factory_girl">factory_girl</a> rather than fixtures.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.tristanmedia.com/2010/07/testing-http-basic-authentication-with-rspec-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Rails 3, RSpec, Mongoid and Database Cleaner</title>
		<link>http://blog.tristanmedia.com/2010/07/rails-3-rspec-and-database-cleaner/</link>
		<comments>http://blog.tristanmedia.com/2010/07/rails-3-rspec-and-database-cleaner/#comments</comments>
		<pubDate>Mon, 05 Jul 2010 21:59:34 +0000</pubDate>
		<dc:creator>Barry</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[mongoid]]></category>
		<category><![CDATA[rspec]]></category>

		<guid isPermaLink="false">http://blog.tristanmedia.com/?p=88</guid>
		<description><![CDATA[After wrestling with various combinations of cleaning out my database between tests, this is what I'm using on a new Rails 3 application that uses Mongoid, RSpec 2, and Database Cleaner. I have one table (neighborhoods) which is populated using rake db:seed, so I'm excluding that from the cleanup. Put this into your spec/spec_helper.rb: require [...]]]></description>
			<content:encoded><![CDATA[<p>After wrestling with various combinations of cleaning out my database between tests, this is what I'm using on a new Rails 3 application that uses <a href="http://mongoid.org/">Mongoid</a>, <a href="http://github.com/rspec/rspec-rails">RSpec 2</a>, and <a href="http://github.com/bmabey/database_cleaner">Database Cleaner</a>.  I have one table (neighborhoods) which is populated using rake db:seed, so I'm excluding that from the cleanup.</p>
<p>Put this into your spec/spec_helper.rb:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'database_cleaner'</span>
&nbsp;
RSpec.<span style="color:#9900CC;">configure</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>config<span style="color:#006600; font-weight:bold;">|</span>
  config.<span style="color:#9900CC;">mock_with</span> <span style="color:#ff3333; font-weight:bold;">:rspec</span>
&nbsp;
  config.<span style="color:#9900CC;">before</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:each</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">do</span>
    DatabaseCleaner.<span style="color:#9900CC;">orm</span> = <span style="color:#996600;">&quot;mongoid&quot;</span> 
    DatabaseCleaner.<span style="color:#9900CC;">strategy</span> = <span style="color:#ff3333; font-weight:bold;">:truncation</span>, <span style="color:#006600; font-weight:bold;">&#123;</span>:except <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">%</span>w<span style="color:#006600; font-weight:bold;">&#91;</span> neighborhoods <span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#125;</span>
    DatabaseCleaner.<span style="color:#9900CC;">clean</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://blog.tristanmedia.com/2010/07/rails-3-rspec-and-database-cleaner/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Quick fix for moving to Vlad the Deployer 2.0.0 with git</title>
		<link>http://blog.tristanmedia.com/2009/09/2-quick-fixes-for-moving-to-vlad-the-deployer-2-0-0/</link>
		<comments>http://blog.tristanmedia.com/2009/09/2-quick-fixes-for-moving-to-vlad-the-deployer-2-0-0/#comments</comments>
		<pubDate>Wed, 09 Sep 2009 19:43:57 +0000</pubDate>
		<dc:creator>Barry</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[deployment]]></category>
		<category><![CDATA[git]]></category>
		<category><![CDATA[vlad]]></category>

		<guid isPermaLink="false">http://blog.tristanmedia.com/?p=76</guid>
		<description><![CDATA[I just upgraded my dev machine to version 2.0.0 of Vlad the Deployer. I got one unexpected error -- "Please specify the deploy path via the :deploy_to variable" -- but here is how I fixed it: git support is now a separate gem, so remember to run sudo gem install vlad-git I also had some [...]]]></description>
			<content:encoded><![CDATA[<p>I just upgraded my dev machine to version 2.0.0 of <a href="http://rubyhitsquad.com/Vlad_the_Deployer.html">Vlad the Deployer</a>. I got one unexpected error -- "Please specify the deploy path via the :deploy_to variable" -- but here is how I fixed it:</p>
<p>git support is now a separate gem, so remember to run</p>
<pre>
sudo gem install vlad-git
</pre>
<p>I also had some problems when version 1.4.0 was also on my machine, so I uninstalled that one with:</p>
<pre>
sudo gem uninstall vlad -v "1.4.0"
</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.tristanmedia.com/2009/09/2-quick-fixes-for-moving-to-vlad-the-deployer-2-0-0/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using Amazon&#8217;s CloudFront with Rails &amp; Paperclip</title>
		<link>http://blog.tristanmedia.com/2009/09/using-amazons-cloudfront-with-rails-and-paperclip/</link>
		<comments>http://blog.tristanmedia.com/2009/09/using-amazons-cloudfront-with-rails-and-paperclip/#comments</comments>
		<pubDate>Wed, 09 Sep 2009 00:01:57 +0000</pubDate>
		<dc:creator>Barry</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[cloudfront]]></category>
		<category><![CDATA[paperclip]]></category>
		<category><![CDATA[s3]]></category>

		<guid isPermaLink="false">http://blog.tristanmedia.com/?p=56</guid>
		<description><![CDATA[It took me a bit of experimentation, and I never found an example in a single place that showed how to set it up exactly how I wanted, so here is my code in my model for storing images used by the ArtCat calendar on Amazon S3. I am using Paperclip version 2.3.1. First you [...]]]></description>
			<content:encoded><![CDATA[<p>It took me a bit of experimentation, and I never found an example in a single place that showed how to set it up exactly how I wanted, so here is my code in my model for storing images used by the <a href="http://www.artcat.com/">ArtCat</a> calendar on <a href="http://aws.amazon.com/s3/">Amazon S3</a>.  I am using <a href="http://github.com/thoughtbot/paperclip/tree/master">Paperclip</a> version 2.3.1.</p>
<p>First you will need to set up the distribution in Amazon for your given bucket, so that you have a URL to use for the :s3_host_alist value. I also set up a <a href="http://docs.amazonwebservices.com/AmazonCloudFront/latest/DeveloperGuide/index.html?CNAMEs.html">CNAME</a> so that I can use a nice url like calcdn.artcat.com.</p>
<p>Note that I don't want to store any images other than my resized ones, so my :default_style is set to :original.  Some of these values are actually constants in my config files, but I've replaced those here to make it more clear.</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">    has_attached_file <span style="color:#ff3333; font-weight:bold;">:image</span>,
      <span style="color:#ff3333; font-weight:bold;">:storage</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'s3'</span>,
      <span style="color:#ff3333; font-weight:bold;">:s3_credentials</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;#{RAILS_ROOT}/config/s3_credentials.yml&quot;</span>,
      <span style="color:#ff3333; font-weight:bold;">:bucket</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'artcal-production'</span>,
      <span style="color:#ff3333; font-weight:bold;">:s3_host_alias</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'calcdn.artcat.com'</span>,
      <span style="color:#ff3333; font-weight:bold;">:url</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">':s3_alias_url'</span>,
      <span style="color:#ff3333; font-weight:bold;">:path</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;images/:class/:id_:timestamp.:style.:extension&quot;</span>,
      <span style="color:#ff3333; font-weight:bold;">:styles</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#ff3333; font-weight:bold;">:thumb</span>  <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'60x60#'</span>, <span style="color:#ff3333; font-weight:bold;">:medium</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'270x200#'</span>, <span style="color:#ff3333; font-weight:bold;">:original</span>  <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'600x600&gt;'</span> <span style="color:#006600; font-weight:bold;">&#125;</span>,
      <span style="color:#ff3333; font-weight:bold;">:default_style</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:original</span>,
      <span style="color:#ff3333; font-weight:bold;">:default_url</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'http://cdn1.artcat.com/pixel.gif'</span>,
      <span style="color:#ff3333; font-weight:bold;">:s3_headers</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#996600;">'Expires'</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> 1.<span style="color:#9900CC;">year</span>.<span style="color:#9900CC;">from_now</span>.<span style="color:#9900CC;">httpdate</span> <span style="color:#006600; font-weight:bold;">&#125;</span>,
      <span style="color:#ff3333; font-weight:bold;">:convert_options</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#ff3333; font-weight:bold;">:all</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'-strip -trim'</span> <span style="color:#006600; font-weight:bold;">&#125;</span></pre></div></div>

<p>Note that you do NOT have to set the ActionController::Base.asset_host to your CNAME for images.  Paperclip just handles it as expected for these images.</p>
<p>You'll notice an interpolation in the :path that is not standard.  Thanks to this Intridea Company Blog <a href="http://www.intridea.com/2009/7/8/amazon-cloudfront-preventing-stale-assets?blog=company">post</a> I learned that I will need to change my image names when they are updated.  CloudFront will not update my image due to that Expires header I set above for a whole year, which is not what we want to happen.  I solved this by including the timestamp based on the updated_at value for the image.  Based on that Intridea post, this is the code I added to config/initalizers/paperclib.rb.</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">Paperclip.<span style="color:#9900CC;">interpolates</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:timestamp</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>attachment, style<span style="color:#006600; font-weight:bold;">|</span>
  attachment.<span style="color:#9900CC;">instance_read</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:updated_at</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">to_i</span>  
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>At first I was storing the images on the file system and serving them via Apache.  Moving them to CloudFront improved my page load times by at least 50%, and means that I don't have to run as powerful as server to handle a lot of traffic on this image-heavy site as I might otherwise need.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.tristanmedia.com/2009/09/using-amazons-cloudfront-with-rails-and-paperclip/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>
