<?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>42 &#187; file_column plugin</title>
	<atom:link href="http://www.42.mach7x.com/tag/file_column-plugin/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.42.mach7x.com</link>
	<description>Thoughts and tips about programming with Ruby on Rails</description>
	<lastBuildDate>Wed, 01 Feb 2012 14:38:36 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Keeping uploaded files between deployments</title>
		<link>http://www.42.mach7x.com/2007/11/26/keeping-uploaded-files-between-deployments/</link>
		<comments>http://www.42.mach7x.com/2007/11/26/keeping-uploaded-files-between-deployments/#comments</comments>
		<pubDate>Mon, 26 Nov 2007 15:58:59 +0000</pubDate>
		<dc:creator>kosmas</dc:creator>
				<category><![CDATA[ruby on rails]]></category>
		<category><![CDATA[capistrano]]></category>
		<category><![CDATA[deployment]]></category>
		<category><![CDATA[file_column plugin]]></category>
		<category><![CDATA[subversion]]></category>

		<guid isPermaLink="false">http://www.42.mach7x.com/2007/11/26/keeping-uploaded-files-between-deployments/</guid>
		<description><![CDATA[Problem You are using file_column plugin (or maybe another plugin?), to upload files in your ruby on rails application. Because the files are big you don&#8217;t want to have a different copy stored in your subversion repository for each different deployment version. You want to keep a common folder with all your uploaded files, and [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Problem</strong><br />
You are using file_column plugin (or maybe another plugin?), to upload files in your ruby on rails application. Because the files are big you don&#8217;t want to have a different copy stored in your subversion repository for each different deployment version. You want to keep a common folder with all your uploaded files, and use it with every different deployment version.</p>
<p><strong>Solution</strong><br />
For the example, we will have a numbers table that has two file_column uploadable columns (intro,voice_mail), with the following migration:</p>
<pre class="code">
class CreateNumbers &lt; ActiveRecord::Migration
  def self.up
    create_table :numbers do |t|
      t.column :customer_id, :int, :null =&gt; false
      t.column :phone_no, :string, :null =&gt; false
      t.column :intro, :string
      t.column :vmail, :string
      t.column :created_at, :datetime
      t.column :updated_at, :datetime
    end

  def self.down
    drop_table :numbers
  end
end</pre>
<ol>
<li>If you already have used cap deploy or cap setup you should have a shared folder in your deployment server.<br />
You should copy the intro and vmail folders that should be located on your public/number folder on your local development client, on a folder called number in your development server in your shared folder.</li>
<li>Create a file in your local pc in lib/cap_recipes.rb:
<pre class="code">
Capistrano.configuration(:must_exist).load do

  desc "Keep generated uploaded files between deployments"
    task :after_symlink do
       run "rm -drf #{deploy_to}/#{current_dir}/public/number"
       sudo "ln -nfs #{shared_path}/number #{deploy_to}/#{current_dir}/public"
    end
  end</pre>
<p>Be careful with the naming of the task as (at least for capistrano 1.4 that I&#8217;m using), it must have a special name as after_symlink.<br />
Also be careful that if you try to use before_symlink, it won&#8217;t work as the current symlink won&#8217;t be setup.</li>
<li>In your config/deploy.rb file add at the top the following:
<pre class="code">require 'lib/cap_recipes'</pre>
</li>
<li>Now you should be ready to deploy your new version so:
<pre class="code">svn -m "added customised capistrano recipes" commit</pre>
<p>make sure that you check in your version in subversion, and then:</p>
<pre class="code">cap deploy</pre>
<p>you should be able to see a link in your current/public folder called number that points to the shared/number folder that hold all the uploaded files.</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://www.42.mach7x.com/2007/11/26/keeping-uploaded-files-between-deployments/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

