<?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>Ryan Kanno: The diary of an Enginerd in Hawaii&#187; Rails</title>
	<atom:link href="http://blog.localkinegrinds.com/category/technology/rails/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.localkinegrinds.com</link>
	<description>Everything you&#039;ve ever thought, but never had the balls to say.</description>
	<lastBuildDate>Thu, 05 Aug 2010 20:59:37 +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>Update: Using Capistrano 2.5 to deploy Rails 2.3 to Webfaction</title>
		<link>http://blog.localkinegrinds.com/2009/07/27/update-using-capistrano-2-5-to-deploy-rails-2-3-to-webfaction/</link>
		<comments>http://blog.localkinegrinds.com/2009/07/27/update-using-capistrano-2-5-to-deploy-rails-2-3-to-webfaction/#comments</comments>
		<pubDate>Mon, 27 Jul 2009 09:41:07 +0000</pubDate>
		<dc:creator>ryankanno</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[WebFaction]]></category>
		<category><![CDATA[capistrano]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[ruby on rails]]></category>

		<guid isPermaLink="false">http://blog.localkinegrinds.com/?p=366</guid>
		<description><![CDATA[Update Having been a Capistrano user for a few years, I absolutely love sweet, sweet automation. A few months ago, I wrote a blog about how to use Capistrano to deploy to WebFaction. However, since that post, the winds of change have swept through the Rails and Capistrano community with the release of Rails 2.3 [...]]]></description>
			<content:encoded><![CDATA[<h2>Update</h2>
<p>Having been a <a href="http://www.capify.org/">Capistrano</a> user for a few years, I absolutely love sweet, sweet automation.  A few months ago, I wrote a blog about <a href="http://blog.localkinegrinds.com/2008/09/16/using-capistrano-to-deploy-to-webfaction/">how to use Capistrano to deploy to WebFaction</a>.  However, since that post, the winds of change have swept through the Rails and Capistrano community with the release of Rails 2.3 and Capistrano 2.5.  WebFaction&#8217;s Ruby installation precludes you from taking advantage of these great updates, so I&#8217;ve come up with a little update to my previous post.</p>
<hr/>
<p><a href="http://blog.localkinegrinds.com/wp-content/uploads/2008/09/automator-icon.jpg" rel="lightbox[366]"><img src="http://blog.localkinegrinds.com/wp-content/uploads/2008/09/automator-icon.jpg" alt="" title="automator-icon" width="200" height="200" class="alignright size-full wp-image-233" /></a></p>
<h2>Learn to Change, Change to Learn</h2>
<p>To be able to deploy Rails 2.3 with Capistrano 2.5, we&#8217;ll first have to jump through a few hoops.  Nice, easy hoops, mind you, but still hoops nonetheless.</p>
<h3>Your own Ruby installation</h3>
<p>You&#8217;ll have to install a custom Ruby installation into your WebFaction home directory.  By following Step 1 <a href="https://help.webfaction.com/index.php?_m=knowledgebase&#038;_a=viewarticle&#038;kbarticleid=89&#038;nav=0,21">here</a>, you&#8217;ll have a working Ruby 1.8.7 installation and RubyGem 1.3.  You&#8217;ll need these if you want to deploy a Rails 2.3 application.  Also, install a version of Mongrel tied to your Ruby installation.</p>
<p><strong>Note:</strong> Typically, I like to install custom installations into ~/opt/local/lib/.  </p>
<h3>Edit Autostart.cgi</h3>
<p>You&#8217;ll have to make a few edits to a few files from <a href="http://blog.localkinegrinds.com/2008/09/16/using-capistrano-to-deploy-to-webfaction/">my previous blog post</a>.</p>
<p>Next, open up your favorite editor of choice (*cough*vi*cough*) and edit the <strong>autostart.cgi</strong> file. Jump to the end of the file and comment out the following line from my previous blog:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="python" style="font-family:monospace;">&nbsp;
<span style="color: #808080; font-style: italic;"># os.system('/usr/local/bin/mongrel_rails start -c /home/&lt;webfaction_username&gt;/webapps-releases/&lt;webfaction_app_name&gt;/current -d -e production -P /home/&lt;webfaction_username&gt;/webapps/&lt;webfaction_app_name&gt;/log/mongrel.pid -p &lt;port&gt;')</span></pre></td></tr></table></div>

<p>and change it to the following:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="python" style="font-family:monospace;">&nbsp;
 <span style="color: #dc143c;">os</span>.<span style="color: black;">system</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'/home/&lt;webfaction_username&gt;/opt/local/lib/ruby1.8/lib/ruby/gems/1.8/bin/mongrel_rails start -c /home/&lt;webfaction_username&gt;/webapps-releases/&lt;webfaction_app_name&gt;/current -d -e production -P /home/&lt;webfaction_username&gt;/webapps/&lt;webfaction_app_name&gt;/log/mongrel.pid -p &lt;port&gt;'</span><span style="color: black;">&#41;</span></pre></td></tr></table></div>

<p><strong>Notice:</strong> We&#8217;re using the path to Mongrel tied to our custom Ruby installation!  This might be different in your installation!</p>
<h3>Edit the Capfile</h3>
<p>In my previous blog, we placed a custom <strong>deploy.rb</strong> into the config directory.  With the latest version of Capistrano, you no longer need to do this.  Rather, place the following into a file called <strong>Capfile</strong> in the root of your Rails project.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;">&nbsp;
<span style="color:#CC0066; font-weight:bold;">load</span> <span style="color:#996600;">'deploy'</span>
&nbsp;
set <span style="color:#ff3333; font-weight:bold;">:webfaction_username</span>, <span style="color:#996600;">&quot;&lt;webfaction_username&gt;&quot;</span>
set <span style="color:#ff3333; font-weight:bold;">:webfaction_db_type</span>, <span style="color:#996600;">&quot;&lt;webfaction_db_type&gt;&quot;</span>
set <span style="color:#ff3333; font-weight:bold;">:webfaction_db</span>, <span style="color:#996600;">&quot;&lt;webfaction_db&gt;&quot;</span>
set <span style="color:#ff3333; font-weight:bold;">:webfaction_db_username</span>, <span style="color:#996600;">&quot;&lt;webfaction_db_username&gt;&quot;</span>
set <span style="color:#ff3333; font-weight:bold;">:webfaction_port</span>, <span style="color:#996600;">&quot;&lt;webfaction_port (get from autostart.cgi)&gt;&quot;</span>
set <span style="color:#ff3333; font-weight:bold;">:database_yml_template</span>, <span style="color:#996600;">&quot;database.example.yml&quot;</span>
&nbsp;
set <span style="color:#ff3333; font-weight:bold;">:application</span>, <span style="color:#996600;">&quot;test&quot;</span>
set <span style="color:#ff3333; font-weight:bold;">:deploy_to</span>, <span style="color:#996600;">&quot;/home/#{webfaction_username}/webapps-releases/#{application}&quot;</span>
&nbsp;
set <span style="color:#ff3333; font-weight:bold;">:scm</span>, <span style="color:#ff3333; font-weight:bold;">:subversion</span>
set <span style="color:#ff3333; font-weight:bold;">:scm_user</span>, <span style="color:#996600;">&quot;&lt;scm_username&gt;&quot;</span>
set <span style="color:#ff3333; font-weight:bold;">:scm_password</span>, <span style="color:#CC0066; font-weight:bold;">Proc</span>.<span style="color:#9900CC;">new</span> <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#6666ff; font-weight:bold;">Capistrano::CLI</span>.<span style="color:#9900CC;">password_prompt</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;Subversion password for #{scm_user}: &quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#125;</span>
set <span style="color:#ff3333; font-weight:bold;">:repository</span>, <span style="color:#CC0066; font-weight:bold;">Proc</span>.<span style="color:#9900CC;">new</span> <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#996600;">&quot;--username #{scm_user} --password #{scm_password} --no-auth-cache &lt;http://path/to/your/svn/goes/here/&gt;&quot;</span><span style="color:#006600; font-weight:bold;">&#125;</span> 
&nbsp;
set <span style="color:#ff3333; font-weight:bold;">:user</span>, <span style="color:#996600;">&quot;#{webfaction_username}&quot;</span>
set <span style="color:#ff3333; font-weight:bold;">:use_sudo</span>, <span style="color:#0000FF; font-weight:bold;">false</span> 
&nbsp;
set <span style="color:#ff3333; font-weight:bold;">:domain</span>, <span style="color:#996600;">&quot;&lt;webfaction_domain&gt;&quot;</span>
&nbsp;
role <span style="color:#ff3333; font-weight:bold;">:app</span>, domain
role <span style="color:#ff3333; font-weight:bold;">:web</span>, domain
role <span style="color:#ff3333; font-weight:bold;">:db</span>,  domain, <span style="color:#ff3333; font-weight:bold;">:primary</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">true</span>
&nbsp;
desc <span style="color:#996600;">&quot;Symlink public to what webfaction expects the webroot to be&quot;</span>
task <span style="color:#ff3333; font-weight:bold;">:after_symlink</span>, <span style="color:#ff3333; font-weight:bold;">:roles</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:web</span> <span style="color:#9966CC; font-weight:bold;">do</span>
  run <span style="color:#996600;">&quot;ln -nfs #{release_path}/public /home/#{webfaction_username}/webapps/#{application}/&quot;</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
namespace <span style="color:#ff3333; font-weight:bold;">:deploy</span> <span style="color:#9966CC; font-weight:bold;">do</span>
&nbsp;
  <span style="color:#008000; font-style:italic;"># Taken from http://jonathan.tron.name/2006/07/15/capistrano-password-prompt-tips </span>
  <span style="color:#008000; font-style:italic;"># Thanks Jonathan! :)</span>
  desc <span style="color:#996600;">&quot;Creates the database configuration on the fly&quot;</span>
  task <span style="color:#ff3333; font-weight:bold;">:create_database_configuration</span>, <span style="color:#ff3333; font-weight:bold;">:roles</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:app</span> <span style="color:#9966CC; font-weight:bold;">do</span>
    <span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">&quot;yaml&quot;</span>
    set <span style="color:#ff3333; font-weight:bold;">:production_db_password</span>, <span style="color:#CC0066; font-weight:bold;">proc</span> <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#6666ff; font-weight:bold;">Capistrano::CLI</span>.<span style="color:#9900CC;">password_prompt</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;Remote production database password: &quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#125;</span>
&nbsp;
    db_config = <span style="color:#CC00FF; font-weight:bold;">YAML</span>::load_file<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;config/#{database_yml_template}&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    db_config.<span style="color:#9900CC;">delete</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'test'</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    db_config.<span style="color:#9900CC;">delete</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'development'</span><span style="color:#006600; font-weight:bold;">&#41;</span>
&nbsp;
    db_config<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'production'</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'adapter'</span><span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#996600;">&quot;#{webfaction_db_type}&quot;</span>
    db_config<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'production'</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'database'</span><span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#996600;">&quot;#{webfaction_db}&quot;</span>
    db_config<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'production'</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'username'</span><span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#996600;">&quot;#{webfaction_db_username}&quot;</span>
    db_config<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'production'</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'password'</span><span style="color:#006600; font-weight:bold;">&#93;</span> = production_db_password
    db_config<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'production'</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'host'</span><span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#996600;">&quot;localhost&quot;</span>
&nbsp;
    put <span style="color:#CC00FF; font-weight:bold;">YAML</span>::dump<span style="color:#006600; font-weight:bold;">&#40;</span>db_config<span style="color:#006600; font-weight:bold;">&#41;</span>, <span style="color:#996600;">&quot;#{release_path}/config/database.yml&quot;</span>, <span style="color:#ff3333; font-weight:bold;">:mode</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> 0664
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  after <span style="color:#996600;">&quot;deploy:update_code&quot;</span>, <span style="color:#996600;">&quot;deploy:create_database_configuration&quot;</span>
&nbsp;
  desc <span style="color:#996600;">&quot;Redefine deploy:start&quot;</span>
  task <span style="color:#ff3333; font-weight:bold;">:start</span>, <span style="color:#ff3333; font-weight:bold;">:roles</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:app</span> <span style="color:#9966CC; font-weight:bold;">do</span>
    invoke_command <span style="color:#996600;">&quot;/opt/local/lib/ruby1.8/lib/ruby/gems/1.8/bin/mongrel_rails start -c #{deploy_to}/current -d -e production -P /home/#{webfaction_username}/webapps/#{application}/log/mongrel.pid -p #{webfaction_port}&quot;</span>, <span style="color:#ff3333; font-weight:bold;">:via</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> run_method
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  desc <span style="color:#996600;">&quot;Redefine deploy:restart&quot;</span>
  task <span style="color:#ff3333; font-weight:bold;">:restart</span>, <span style="color:#ff3333; font-weight:bold;">:roles</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:app</span> <span style="color:#9966CC; font-weight:bold;">do</span>
    invoke_command <span style="color:#996600;">&quot;/opt/local/lib/ruby1.8/lib/ruby/gems/1.8/bin/mongrel_rails restart -c #{deploy_to}/current -P /home/#{webfaction_username}/webapps/#{application}/log/mongrel.pid&quot;</span>, <span style="color:#ff3333; font-weight:bold;">:via</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> run_method
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  desc <span style="color:#996600;">&quot;Redefine deploy:stop&quot;</span>
  task <span style="color:#ff3333; font-weight:bold;">:stop</span>, <span style="color:#ff3333; font-weight:bold;">:roles</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:app</span> <span style="color:#9966CC; font-weight:bold;">do</span>
    invoke_command <span style="color:#996600;">&quot;/opt/local/lib/ruby1.8/lib/ruby/gems/1.8/bin/mongrel_rails stop -c #{deploy_to}/current -P /home/#{webfaction_username}/webapps/#{application}/log/mongrel.pid&quot;</span>, <span style="color:#ff3333; font-weight:bold;">:via</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> run_method
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></td></tr></table></div>

<div style="font:normal 1.1em arial; background-color:#E5F3FF; padding:1em; margin:1em 0; border:1px solid #114477; color:#33415D;"><strong>Note:</strong> Change all the values in tags like <strong>&lt;webfaction_username&gt;</strong>, <strong>&lt;webfaction_db&gt;</strong>, <strong>&lt;webfaction_db_username&gt;</strong>, etc. to those values that fit your configuration!<br/>Otherwise, this file in itself won&#8217;t do you any good.</div>
<p><strong>Now, you should be able to run the standard Capistrano tasks to deploy your application to WebFaction with the latest version of Rails!</strong></p>
<h3>Explanation</h3>
<p>Basically, the only thing I&#8217;ve done is shown you how to update your version of Ruby, RubyGems, Mongrel, and Capistrano to place nicely in WebFaction.  This should allow you to run commands like &#8216;cap deploy:setup&#8217;, &#8216;cap deploy:update&#8217; on your local machine and update your live code on WebFaction&#8217;s servers. Nothing too serious going on here!  As always, feel free to use, steal, take, and/or copy anything on this blog. Hopefully somewhere, someone on the Interwebs will find these tips handy!</p>
<p><strong>And if you find anything wrong with these scripts, don&#8217;t hesitate to leave a comment or email!</strong></p>
<h2>Voila! (Enjoy)</h2>
<img src="http://blog.localkinegrinds.com/?ak_action=api_record_view&id=366&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://blog.localkinegrinds.com/2009/07/27/update-using-capistrano-2-5-to-deploy-rails-2-3-to-webfaction/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Using Capistrano to deploy to WebFaction</title>
		<link>http://blog.localkinegrinds.com/2008/09/16/using-capistrano-to-deploy-to-webfaction/</link>
		<comments>http://blog.localkinegrinds.com/2008/09/16/using-capistrano-to-deploy-to-webfaction/#comments</comments>
		<pubDate>Tue, 16 Sep 2008 16:57:30 +0000</pubDate>
		<dc:creator>ryankanno</dc:creator>
				<category><![CDATA[HowTo]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[WebFaction]]></category>
		<category><![CDATA[capistrano]]></category>
		<category><![CDATA[deploy]]></category>
		<category><![CDATA[mongrel]]></category>
		<category><![CDATA[ror]]></category>
		<category><![CDATA[ruby on rails]]></category>

		<guid isPermaLink="false">http://blog.localkinegrinds.com/?p=215</guid>
		<description><![CDATA[Update If you like to stay on the edge, check out my latest post describing how to use Capistrano 2.5 to deploy Rails 2.3 to Webfaction! There&#8217;s nothing I love more than sweet automation. After spending the better part of an hour searching the great Googs, there was only a single blog I could find [...]]]></description>
			<content:encoded><![CDATA[<h2>Update</h2>
<p>If you like to stay on the edge, check out my latest <a href="http://blog.localkinegrinds.com/2009/07/27/update-using-capistrano-2-5-to-deploy-rails-2-3-to-webfaction/">post describing how to use Capistrano 2.5 to deploy Rails 2.3 to Webfaction</a>!  </p>
<hr/>
<p><a href="http://blog.localkinegrinds.com/wp-content/uploads/2008/09/automator-icon.jpg" rel="lightbox[215]"><img src="http://blog.localkinegrinds.com/wp-content/uploads/2008/09/automator-icon.jpg" alt="" title="automator-icon" width="200" height="200" class="alignright size-full wp-image-233" /></a></p>
<h2>There&#8217;s nothing I love more than sweet automation.</h2>
<p>After spending the better part of an hour searching the great Googs, there was only a single blog I could find describing <a href="http://mega.blaix.com/2007/8/29/capistrano-on-webfaction">how to use Capistrano to deploy to WebFaction</a>.  <em>Unfortunately, Justin was describing a Capistrano 1.4 deployment.</em> I found a <a href="http://forum.webfaction.com/viewtopic.php?id=598">few</a> <a href="http://forum.webfaction.com/viewtopic.php?id=1610">posts</a> on the <a href="http://forum.webfaction.com/">WebFaction forums</a>, but nothing concrete.  So after a few hours fiddling with the technology, here&#8217;s how I configured my <a href="http://www.rubyonrails.org/">Rails</a> 2.1.1 project to use <a href="http://www.capify.org/">Capistrano</a> 2.5 to deploy to <a href="http://www.webfaction.com">WebFaction</a>.</p>
<h3>Assumptions</h3>
<p>Before getting started, I&#8217;m going to assume the following:</p>
<ul>
<li>I&#8217;m assuming you&#8217;ve already used the one-click WebFaction goodness to create a brand new Rails application in ~/webapps/&lt;application_name&gt;.  If you don&#8217;t know what I&#8217;m referring to, make sure to check out the <a href="http://www.webfaction.com/demos/rails-typo">Rails and Typo Demo screencast</a>.  Make sure you have a domain, application, and website configured.</li>
<li>I&#8217;m also going to assume that your nifty Rails application is safely stored away in either a <a href="http://subversion.tigris.org/">Subversion</a> or <a href="http://git.or.cz/">Git</a> repository and you&#8217;ve frozen Rails in your application.</li>
<li>Finally, I&#8217;m going to assume you setup your database via <a href="http://www.webfaction.com/screencasts/control-panel-demo/demo.html">WebFaction&#8217;s control panel</a>.
</ul>
<h3>Installing Capistrano</h3>
<p>The very first thing you have to do is install Capistrano on your <em>local machine</em> by issuing the following command:</p>
<pre class="console">
$ gem install -y capistrano
</pre>
<p>After installing Capistrano, the first thing you have to do is to &#8220;capify&#8221; your local Rails project.  Change into your project&#8217;s root directory and issue the following command:</p>
<pre class="console">
$ capify .
</pre>
<p>This configures your Rails project to play nicely with Capistrano.  Two files should&#8217;ve been created; <strong>Capfile</strong> in the project root and <strong>config/deploy.rb</strong>.  The deploy.rb file contains the Rails project application-specific deployment configuration.</p>
<h3>Configuring WebFaction</h3>
<p>Jumping back to WebFaction, I followed a few of the steps in <a href="http://mega.blaix.com/2007/8/29/capistrano-on-webfaction">Justin&#8217;s blog</a>.  First thing&#8217;s first, ssh into your WebFaction account and create a directory called <strong>webapps-releases</strong> in your home directory.  This directory is where we&#8217;re going to deploy the application to.</p>
<p>Since you&#8217;ve already configured a Rails application at ~/webapps/&lt;application_name&gt;, change into that directory.  You should see a standard Rails project with the exception of an extra file called autostart.cgi.  Remove everything in the directory except the autostart.cgi file by issuing the following commands:</p>
<pre class="console">
$ cd ~/webapps/&lt;application_name&gt;
$ mv autostart.cgi ~/
$ rm -rf *
$ mv ~/autostart.cgi .
</pre>
<p>Once the directory is clear, create a symlink to the log directory that will be in the webapps-releases directory we created earlier.</p>
<pre class="console">
$ ln -s ~/webapps-releases/&lt;application_name&gt;/shared/log ~/webapps/&lt;application_name&gt;/log
</pre>
<p><strong>Note:</strong> I&#8217;m assuming here that the WebFaction app and the Rails application have identical names.</p>
<p>Next, open up your favorite editor of choice (*cough*Vi*cough*) and edit the <strong>autostart.cgi</strong> file.  Jump to the end of the file and comment out the following line:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="python" style="font-family:monospace;">&nbsp;
<span style="color: #808080; font-style: italic;"># os.system('/usr/local/bin/mongrel_rails start -d -e production -P /home/&lt;webfaction_username&gt;/webapps/&lt;webfaction_app_name&gt;/log/mongrel.pid -p &lt;port&gt;')</span></pre></td></tr></table></div>

<p>and right below it, cut and paste the following:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="python" style="font-family:monospace;">&nbsp;
  <span style="color: #dc143c;">os</span>.<span style="color: black;">system</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'/usr/local/bin/mongrel_rails start -c /home/&lt;webfaction_username&gt;/webapps-releases/&lt;webfaction_app_name&gt;/current -d -e production -P /home/&lt;webfaction_username&gt;/webapps/&lt;webfaction_app_name&gt;/log/mongrel.pid -p &lt;port&gt;'</span><span style="color: black;">&#41;</span></pre></td></tr></table></div>

<h3>Creating your custom deploy.rb</h3>
<p>After configuring WebFaction, we have to configure the Capistrano application deployment configuration.  On your local machine, find the file <strong>config/deploy.rb</strong> and replace it with the one below.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;">&nbsp;
set <span style="color:#ff3333; font-weight:bold;">:webfaction_username</span>, <span style="color:#996600;">&quot;&lt;webfaction_username&gt;&quot;</span>
set <span style="color:#ff3333; font-weight:bold;">:webfaction_db_type</span>, <span style="color:#996600;">&quot;&lt;webfaction_db_type&gt;&quot;</span>
set <span style="color:#ff3333; font-weight:bold;">:webfaction_db</span>, <span style="color:#996600;">&quot;&lt;webfaction_db&gt;&quot;</span>
set <span style="color:#ff3333; font-weight:bold;">:webfaction_db_username</span>, <span style="color:#996600;">&quot;&lt;webfaction_db_username&gt;&quot;</span>
set <span style="color:#ff3333; font-weight:bold;">:webfaction_port</span>, <span style="color:#996600;">&quot;&lt;webfaction_port (get from autostart.cgi)&gt;&quot;</span>
set <span style="color:#ff3333; font-weight:bold;">:database_yml_template</span>, <span style="color:#996600;">&quot;database.example.yml&quot;</span>
&nbsp;
set <span style="color:#ff3333; font-weight:bold;">:application</span>, <span style="color:#996600;">&quot;test&quot;</span>
set <span style="color:#ff3333; font-weight:bold;">:deploy_to</span>, <span style="color:#996600;">&quot;/home/#{webfaction_username}/webapps-releases/#{application}&quot;</span>
&nbsp;
set <span style="color:#ff3333; font-weight:bold;">:scm</span>, <span style="color:#ff3333; font-weight:bold;">:subversion</span>
set <span style="color:#ff3333; font-weight:bold;">:scm_user</span>, <span style="color:#996600;">&quot;&lt;scm_username&gt;&quot;</span>
set <span style="color:#ff3333; font-weight:bold;">:scm_password</span>, <span style="color:#CC0066; font-weight:bold;">Proc</span>.<span style="color:#9900CC;">new</span> <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#6666ff; font-weight:bold;">Capistrano::CLI</span>.<span style="color:#9900CC;">password_prompt</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;Subversion password for #{scm_user}: &quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#125;</span>
set <span style="color:#ff3333; font-weight:bold;">:repository</span>, <span style="color:#CC0066; font-weight:bold;">Proc</span>.<span style="color:#9900CC;">new</span> <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#996600;">&quot;--username #{scm_user} --password #{scm_password} --no-auth-cache &lt;http://path/to/your/svn/goes/here/&gt;&quot;</span><span style="color:#006600; font-weight:bold;">&#125;</span> 
&nbsp;
set <span style="color:#ff3333; font-weight:bold;">:user</span>, <span style="color:#996600;">&quot;#{webfaction_username}&quot;</span>
set <span style="color:#ff3333; font-weight:bold;">:use_sudo</span>, <span style="color:#0000FF; font-weight:bold;">false</span> 
&nbsp;
set <span style="color:#ff3333; font-weight:bold;">:domain</span>, <span style="color:#996600;">&quot;&lt;webfaction_domain&gt;&quot;</span>
&nbsp;
role <span style="color:#ff3333; font-weight:bold;">:app</span>, domain
role <span style="color:#ff3333; font-weight:bold;">:web</span>, domain
role <span style="color:#ff3333; font-weight:bold;">:db</span>,  domain, <span style="color:#ff3333; font-weight:bold;">:primary</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">true</span>
&nbsp;
desc <span style="color:#996600;">&quot;Symlink public to what webfaction expects the webroot to be&quot;</span>
task <span style="color:#ff3333; font-weight:bold;">:after_symlink</span>, <span style="color:#ff3333; font-weight:bold;">:roles</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:web</span> <span style="color:#9966CC; font-weight:bold;">do</span>
  run <span style="color:#996600;">&quot;ln -nfs #{release_path}/public /home/#{webfaction_username}/webapps/#{application}/&quot;</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
namespace <span style="color:#ff3333; font-weight:bold;">:deploy</span> <span style="color:#9966CC; font-weight:bold;">do</span>
&nbsp;
  <span style="color:#008000; font-style:italic;"># Taken from http://jonathan.tron.name/2006/07/15/capistrano-password-prompt-tips </span>
  <span style="color:#008000; font-style:italic;"># Thanks Jonathan! :)</span>
  desc <span style="color:#996600;">&quot;Creates the database configuration on the fly&quot;</span>
  task <span style="color:#ff3333; font-weight:bold;">:create_database_configuration</span>, <span style="color:#ff3333; font-weight:bold;">:roles</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:app</span> <span style="color:#9966CC; font-weight:bold;">do</span>
    <span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">&quot;yaml&quot;</span>
    set <span style="color:#ff3333; font-weight:bold;">:production_db_password</span>, <span style="color:#CC0066; font-weight:bold;">proc</span> <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#6666ff; font-weight:bold;">Capistrano::CLI</span>.<span style="color:#9900CC;">password_prompt</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;Remote production database password: &quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#125;</span>
&nbsp;
    db_config = <span style="color:#CC00FF; font-weight:bold;">YAML</span>::load_file<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;config/#{database_yml_template}&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    db_config.<span style="color:#9900CC;">delete</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'test'</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    db_config.<span style="color:#9900CC;">delete</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'development'</span><span style="color:#006600; font-weight:bold;">&#41;</span>
&nbsp;
    db_config<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'production'</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'adapter'</span><span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#996600;">&quot;#{webfaction_db_type}&quot;</span>
    db_config<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'production'</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'database'</span><span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#996600;">&quot;#{webfaction_db}&quot;</span>
    db_config<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'production'</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'username'</span><span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#996600;">&quot;#{webfaction_db_username}&quot;</span>
    db_config<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'production'</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'password'</span><span style="color:#006600; font-weight:bold;">&#93;</span> = production_db_password
    db_config<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'production'</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'host'</span><span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#996600;">&quot;localhost&quot;</span>
&nbsp;
    put <span style="color:#CC00FF; font-weight:bold;">YAML</span>::dump<span style="color:#006600; font-weight:bold;">&#40;</span>db_config<span style="color:#006600; font-weight:bold;">&#41;</span>, <span style="color:#996600;">&quot;#{release_path}/config/database.yml&quot;</span>, <span style="color:#ff3333; font-weight:bold;">:mode</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> 0664
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  after <span style="color:#996600;">&quot;deploy:update_code&quot;</span>, <span style="color:#996600;">&quot;deploy:create_database_configuration&quot;</span>
&nbsp;
  desc <span style="color:#996600;">&quot;Redefine deploy:start&quot;</span>
  task <span style="color:#ff3333; font-weight:bold;">:start</span>, <span style="color:#ff3333; font-weight:bold;">:roles</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:app</span> <span style="color:#9966CC; font-weight:bold;">do</span>
    invoke_command <span style="color:#996600;">&quot;/usr/local/bin/mongrel_rails start -c #{deploy_to}/current -d -e production -P /home/#{webfaction_username}/webapps/#{application}/log/mongrel.pid -p #{webfaction_port}&quot;</span>, <span style="color:#ff3333; font-weight:bold;">:via</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> run_method
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  desc <span style="color:#996600;">&quot;Redefine deploy:restart&quot;</span>
  task <span style="color:#ff3333; font-weight:bold;">:restart</span>, <span style="color:#ff3333; font-weight:bold;">:roles</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:app</span> <span style="color:#9966CC; font-weight:bold;">do</span>
    invoke_command <span style="color:#996600;">&quot;/usr/local/bin/mongrel_rails restart -c #{deploy_to}/current -P /home/#{webfaction_username}/webapps/#{application}/log/mongrel.pid&quot;</span>, <span style="color:#ff3333; font-weight:bold;">:via</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> run_method
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  desc <span style="color:#996600;">&quot;Redefine deploy:stop&quot;</span>
  task <span style="color:#ff3333; font-weight:bold;">:stop</span>, <span style="color:#ff3333; font-weight:bold;">:roles</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:app</span> <span style="color:#9966CC; font-weight:bold;">do</span>
    invoke_command <span style="color:#996600;">&quot;/usr/local/bin/mongrel_rails stop -c #{deploy_to}/current -P /home/#{webfaction_username}/webapps/#{application}/log/mongrel.pid&quot;</span>, <span style="color:#ff3333; font-weight:bold;">:via</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> run_method
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></td></tr></table></div>

<div style="font:normal 1.1em arial; background-color:#E5F3FF; padding:1em; margin:1em 0; border:1px solid #114477; color:#33415D;"><strong>Note:</strong> Change all the values in tags like <strong>&lt;webfaction_username&gt;</strong>, <strong>&lt;webfaction_db&gt;</strong>, <strong>&lt;webfaction_db_username&gt;</strong>, etc. to those values that fit your configuration!<br/>Otherwise, this file in itself won&#8217;t do you any good.</div>
<p><strong>Props out to <a href="http://jonathan.tron.name/">Jonathan</a> for the fantastic Capistrano tips!</strong></p>
<p>After copying the deploy.rb file and editing the appropriate variables, run the following command in your Rails project&#8217;s root directory:</p>
<pre class="console">
$ cap deploy:setup
</pre>
<p>This command creates the appropriate directory structure for Capistrano on the deployment server based upon values set in your deploy.rb.  Next, run the following command to check your dependencies.</p>
<pre class="console">
$ cap deploy:check
</pre>
<p>If everything is successful, you should see a message that reads something like&#8230;<br/></p>
<p><strong>You appear to have all necessary dependencies installed</strong></p>
<p>Next, push your code out to the server using the following command:</p>
<pre class="console">
$ cap deploy:update
</pre>
<p>Finally, to start up your application run the following Capistrano command:</p>
<pre class="console">
$ cap deploy:start
</pre>
<p>Now, you should be able to run the standard Capistrano tasks to deploy your application to WebFaction!</p>
<h3>Explanation</h3>
<p>Most techies like to have an explanation of what&#8217;s going on with the Capistrano deploy.rb.  I could probably write another blog about it, but I&#8217;m lazy (and pressed for time).  The :create_database_configuration task basically writes the database.yml production configuration on the fly (courtesy of this <a href="http://jonathan.tron.name/2006/07/15/capistrano-password-prompt-tips">blog posting</a>).</p>
<p>The basic gyst of the rest of the script is that WebFaction is proxying a Mongrel instance.  The Capistrano deploy.rb override the original deploy:start, deploy:stop, and deploy:restart tasks to run Mongrel commands that WebFaction can understand.  Typically, the default Capistrano tasks run script/spin and reaper, but it was easier just to redefine the task.  <strong>If anyone has any tips/suggestions to improve the script, I&#8217;m all ears!  </strong></p>
<h2>Voila! (Enjoy)</h2>
<img src="http://blog.localkinegrinds.com/?ak_action=api_record_view&id=215&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://blog.localkinegrinds.com/2008/09/16/using-capistrano-to-deploy-to-webfaction/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>ERB block comments in RHTML templates using Ruby on Rails</title>
		<link>http://blog.localkinegrinds.com/2008/05/02/erb-block-comments-in-rhtml-templates-using-ruby-on-rails/</link>
		<comments>http://blog.localkinegrinds.com/2008/05/02/erb-block-comments-in-rhtml-templates-using-ruby-on-rails/#comments</comments>
		<pubDate>Fri, 02 May 2008 14:05:23 +0000</pubDate>
		<dc:creator>ryankanno</dc:creator>
				<category><![CDATA[Projects]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[block comment]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[comment]]></category>
		<category><![CDATA[erb]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[rhtml]]></category>
		<category><![CDATA[ror]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[ruby on rails]]></category>
		<category><![CDATA[snippet]]></category>

		<guid isPermaLink="false">http://blog.localkinegrinds.com/?p=169</guid>
		<description><![CDATA[This blog is simply a reminder to myself more than anything else. After searching the great Googs and reading here, here, and here about commenting out regions in your RHTML templates, I couldn&#8217;t find a (good) solution aside from the () paradigm. Using Rails 1.2.3 (I know, I know&#8230; we&#8217;re old school), to get block [...]]]></description>
			<content:encoded><![CDATA[<div class="bold info">This blog is simply a reminder to myself more than anything else.</div>
<p>After <a href="http://www.google.com/search?q=rhtml+comments&#038;ie=utf-8&#038;oe=utf-8&#038;aq=t&#038;rls=org.mozilla:en-US:official&#038;client=firefox-a">searching the great Googs</a> and reading <a href="http://www.neeraj.name/229/commenting-out-the-code-in-rhtml">here</a>, <a href="http://lists.netisland.net/archives/phillyonrails/phillyonrails-2005/msg00083.html">here</a>, and <a href="http://www.nabble.com/Re:-RHTML-comments-p12844273s27020.html">here</a> about commenting out regions in your RHTML templates, I couldn&#8217;t find a (good) solution aside from the (<... if false ...>) paradigm.  Using Rails 1.2.3 (I know, I know&#8230; we&#8217;re <a href="www.urbandictionary.com/define.php?term=old+school">old school</a>), to get block comments in Rails, the following worked for me, but unfortunately, still wasn&#8217;t recognized by <a href="http://www.netbeans.org/ ">NetBeans</a> 6.0 (Boo!).</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;">&lt;table&gt;
  ...
  &lt;tbody&gt;
    &lt;tr id=&quot;<span style="color:#006600; font-weight:bold;">&lt;%</span>= <span style="color:#996600;">&quot;photographer_#{photographer.id}&quot;</span><span style="color:#006600; font-weight:bold;">%&gt;</span>&quot;&gt;
      &lt;td&gt;<span style="color:#006600; font-weight:bold;">&lt;%</span> 
<span style="color:#000080; font-style:italic;">=begin %&gt;</span>
<span style="color:#006600; font-weight:bold;">&lt;%</span>= h photographer.<span style="color:#9900CC;">first_name</span> <span style="color:#9966CC; font-weight:bold;">unless</span> photographer.<span style="color:#9900CC;">blank</span>? <span style="color:#006600; font-weight:bold;">%&gt;&lt;%</span> 
=<span style="color:#9966CC; font-weight:bold;">end</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
      &lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
  ...
&lt;/table&gt;</pre></td></tr></table></div>

<h2>Happy Coding!</h2>
<img src="http://blog.localkinegrinds.com/?ak_action=api_record_view&id=169&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://blog.localkinegrinds.com/2008/05/02/erb-block-comments-in-rhtml-templates-using-ruby-on-rails/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Installing MIT Simile&#8217;s Timeline locally (w/ Rails integration)</title>
		<link>http://blog.localkinegrinds.com/2007/11/06/installing-mit-similes-timeline-locally-w-rails-integration/</link>
		<comments>http://blog.localkinegrinds.com/2007/11/06/installing-mit-similes-timeline-locally-w-rails-integration/#comments</comments>
		<pubDate>Tue, 06 Nov 2007 17:15:03 +0000</pubDate>
		<dc:creator>ryankanno</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[install]]></category>
		<category><![CDATA[json]]></category>
		<category><![CDATA[local]]></category>
		<category><![CDATA[mit]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[simile]]></category>
		<category><![CDATA[timeline]]></category>

		<guid isPermaLink="false">http://blog.localkinegrinds.com/2007/11/06/installing-mit-similes-timeline-locally-w-rails-integration/</guid>
		<description><![CDATA[Update: 5/24/2009 If you&#8217;re using a newer version of Simile&#8217;s Timeline, 2.3.1 as of this writing, and want to run it on your own local server, check out the comment made by Biju. Thanks Biju! Update: 12/5/2007 Apparently, I&#8217;m still a rookie blogger and I forgot to mention that I was pulling from trunk (-r [...]]]></description>
			<content:encoded><![CDATA[<h3>Update: 5/24/2009</h3>
<div class="update">
If you&#8217;re using a newer version of Simile&#8217;s Timeline, 2.3.1 as of this writing, and want to run it on your own local server, check out the <a href="http://blog.localkinegrinds.com/2007/11/06/installing-mit-similes-timeline-locally-w-rails-integration/comment-page-1/#comment-30020">comment made by Biju</a>.  Thanks Biju!
</div>
<hr />
<h3>Update: 12/5/2007</h3>
<div class="update">
Apparently, I&#8217;m still a rookie blogger and I forgot to mention that I was pulling from trunk (-r 8642).  Don&#8217;t use the tags if you want the code below to work. <img src='http://blog.localkinegrinds.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />   Sorry about that neilo!
</div>
<hr />
<p>Since my past few blogs have been for the <a href="http://www.djangoproject.com" target="_blank">Django</a> community, I&#8217;ll switch it up a little and talk about a visualization widget from those uber-smart kids at <a href="http://www.mit.edu/">MIT</a>.</p>
<div style="text-align:center; margin:auto;"><img src='http://blog.localkinegrinds.com/wp-content/uploads/2007/11/timeline.jpg' alt='Timeline' /></div>
<p>For one of my <a href="http://rubyonrails.org">Rails</a> prototypes at work, I decided to integrate <a href="http://simile.mit.edu/timeline/">Timeline</a>; a pretty neat DHTML-based AJAXy widget for visualizing time-based events.  Using a visual timeline is not only a lot &#8216;purrrrrtier&#8217; than the mundane <a href="http://www.teach-nology.com/web_tools/materials/timelines/">list-style displays</a>, but it also gives a better relative perspective of how events overlap, their duration, etc.  </p>
<p><strong>In any case, I <strike>liked</strike> loved it, and I really wanted to use it.</strong></p>
<p>Since I typically don&#8217;t have access to the Internet at work (I know, I know&#8230; a pseudo-developer without Internet access; welcome to my so-called life), I often have to download libraries and install them locally.  Searching <a href="http://simile.mit.edu/mail/SummarizeList?listId=10">Timeline&#8217;s mailing list archives</a>, I found <a href="http://simile.mit.edu/mail/ReadMsg?listId=10&#038;msgId=19199">one thread</a> concerning the local installation of Exhibit.</p>
<p><strong>Yet, nothing about Timeline.</strong></p>
<p>So with that said, here&#8217;s the edits I made (kudos to <a href="http://www.getfirebug.com/">Firebug developers</a>).  I would&#8217;ve created a patch file, but I was too lazy and the edits were too easy (sorry). <img src='http://blog.localkinegrinds.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />   Search for the following line in <a href="http://simile.mit.edu/repository/timeline/trunk/src/webapp/api/timeline-api.js">timeline-api.js</a> (located in src/webapp/api directory in the downloadable distribution).</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> url <span style="color: #339933;">=</span> useLocalResources <span style="color: #339933;">?</span>
            <span style="color: #3366CC;">&quot;http://127.0.0.1:9999/ajax/api/simile-ajax-api.js?bundle=false&quot;</span> <span style="color: #339933;">:</span>
            <span style="color: #3366CC;">&quot;http://static.simile.mit.edu/ajax/api-2.0/simile-ajax-api.js&quot;</span><span style="color: #339933;">;</span></pre></div></div>

<p>and edit it to the following:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">//var url = useLocalResources ?</span>
<span style="color: #006600; font-style: italic;">//            &quot;http://127.0.0.1:9999/ajax/api/simile-ajax-api.js?bundle=false&quot; :</span>
<span style="color: #006600; font-style: italic;">//            &quot;http://static.simile.mit.edu/ajax/api-2.0/simile-ajax-api.js&quot;;</span>
<span style="color: #003366; font-weight: bold;">var</span> url <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>document.<span style="color: #660066;">location</span>.<span style="color: #660066;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">indexOf</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'https://'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> <span style="color: #339933;">-</span><span style="color: #CC0000;">1</span> <span style="color: #339933;">?</span> <span style="color: #3366CC;">&quot;https&quot;</span> <span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;http&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;://&quot;</span> <span style="color: #339933;">+</span> window.<span style="color: #660066;">location</span>.<span style="color: #660066;">href</span>.<span style="color: #660066;">split</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;/&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">2</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;WEB_URL_TO /src/ajax/api/simile-ajax-api.js?bundle=false&quot;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Basically, instead of using the supplied Jetty webserver, we&#8217;re just editing the url to your local installation of the file.  Remember to change <strong>WEB_URL_TO</strong> to the path to the simile-ajax-api.js file in your own environment.  Typically, one would put this file in a publicly accessible web folder named js, javascript, etc.</p>
<h2>Voila!</h2>
<p>As an added bonus, nowhere in Timeline&#8217;s <a href="http://simile.mit.edu/timeline/docs/">documentation</a> or <a href="http://simile.mit.edu/timeline/examples/">examples</a> does it indicate how to load inline event data.  When I say inline, I mean dynamic data produced as a result of an action; in this case a search query.  I want to be able to query on a set of dates and produce all event data points between those dates.  <a href="http://simile.mit.edu/timeline/docs/create-timelines.html">Timeline&#8217;s typical use case</a>  is to load data from a javascript (.js) file.  Personally, since the data is dynamic, I didn&#8217;t feel like writing a temp file publicly accessible by the web server or creating a <a href="http://en.wikipedia.org/wiki/Representational_State_Transfer">REST</a> action exposing the dynamic data; both of which are viable solutions, the latter more ideal than the former.  I just wanted to write <a href="http://json.org/">JSON</a> inside of the rendered html file and load the Timeline.  To do so, instead of coding the following (like in their <a href="http://simile.mit.edu/timeline/examples/cubism/cubism.html">cubism example</a>):</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">      tl <span style="color: #339933;">=</span> Timeline.<span style="color: #660066;">create</span><span style="color: #009900;">&#40;</span>document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;tl&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> bandInfos<span style="color: #339933;">,</span> Timeline.<span style="color: #660066;">HORIZONTAL</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      tl.<span style="color: #660066;">loadJSON</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;cubism.js&quot;</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>json<span style="color: #339933;">,</span> url<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
           eventSource.<span style="color: #660066;">loadJSON</span><span style="color: #009900;">&#40;</span>json<span style="color: #339933;">,</span> url<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Using a rails example, this is what I included in my view:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;%</span> <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #339933;">@</span>include_timeline <span style="color: #339933;">%&gt;</span>
    <span style="color: #339933;">&lt;%=</span> javascript_include_tag <span style="color: #3366CC;">'PATH_TO/timeline-api.js?timeline-use-local-resources=true'</span> <span style="color: #339933;">%&gt;</span> 
    <span style="color: #339933;">&lt;</span>script<span style="color: #339933;">&gt;</span>
      <span style="color: #003366; font-weight: bold;">var</span> tl<span style="color: #339933;">;</span>
&nbsp;
      <span style="color: #003366; font-weight: bold;">var</span> events <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #339933;">&lt;%</span> <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #339933;">@</span>events <span style="color: #339933;">%&gt;</span>
        <span style="color: #3366CC;">'dateTimeFormat'</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">'iso8601'</span><span style="color: #339933;">,</span>
        <span style="color: #3366CC;">'events'</span><span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span>
          <span style="color: #339933;">&lt;%</span> <span style="color: #339933;">@</span>events.<span style="color: #660066;">each_with_index</span> <span style="color: #000066; font-weight: bold;">do</span> <span style="color: #339933;">|</span>event<span style="color: #339933;">,</span> i<span style="color: #339933;">|</span> <span style="color: #339933;">%&gt;</span>
          <span style="color: #009900;">&#123;</span>
            <span style="color: #339933;">&lt;%</span> <span style="color: #000066; font-weight: bold;">if</span> event.<span style="color: #660066;">start</span> and event.<span style="color: #660066;">end</span> <span style="color: #339933;">%&gt;</span>
             <span style="color: #3366CC;">'start'</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">'&lt;%= event.start.iso8601 %&gt;'</span><span style="color: #339933;">,</span>
             <span style="color: #3366CC;">'end'</span>  <span style="color: #339933;">:</span> <span style="color: #3366CC;">'&lt;%= event.end.iso8601 %&gt;'</span><span style="color: #339933;">,</span>
            <span style="color: #339933;">&lt;%</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #339933;">%&gt;</span>
             <span style="color: #3366CC;">'start'</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">'&lt;%= event.occurred.iso8601 %&gt;'</span><span style="color: #339933;">,</span>
            <span style="color: #339933;">&lt;%</span> end <span style="color: #339933;">%&gt;</span>
            <span style="color: #3366CC;">'title'</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">'&lt;%= event.headline %&gt;'</span><span style="color: #339933;">,</span>
            <span style="color: #3366CC;">'description'</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">'&lt;%= event.description %&gt;'</span>
          <span style="color: #009900;">&#125;</span><span style="color: #339933;">&lt;%</span> <span style="color: #000066; font-weight: bold;">if</span> i <span style="color: #339933;">!=</span> <span style="color: #339933;">@</span>events.<span style="color: #660066;">length</span> <span style="color: #339933;">-</span> <span style="color: #CC0000;">1</span> <span style="color: #339933;">-%&gt;,</span> <span style="color: #339933;">&lt;%</span> end <span style="color: #339933;">-%&gt;</span>
          <span style="color: #339933;">&lt;%</span> end <span style="color: #339933;">%&gt;</span>
        <span style="color: #009900;">&#93;</span>
        <span style="color: #339933;">&lt;%</span> end <span style="color: #339933;">%&gt;</span>       
      <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
      <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #000066;">onLoad</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #003366; font-weight: bold;">var</span> eventSource <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Timeline.<span style="color: #660066;">DefaultEventSource</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
        <span style="color: #003366; font-weight: bold;">var</span> theme <span style="color: #339933;">=</span> Timeline.<span style="color: #660066;">ClassicTheme</span>.<span style="color: #660066;">create</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        theme.<span style="color: #660066;">event</span>.<span style="color: #660066;">label</span>.<span style="color: #660066;">width</span> <span style="color: #339933;">=</span> <span style="color: #CC0000;">250</span><span style="color: #339933;">;</span>
        theme.<span style="color: #660066;">event</span>.<span style="color: #660066;">bubble</span>.<span style="color: #660066;">width</span><span style="color: #339933;">=</span><span style="color: #CC0000;">320</span><span style="color: #339933;">;</span>
        theme.<span style="color: #660066;">event</span>.<span style="color: #660066;">bubble</span>.<span style="color: #660066;">height</span><span style="color: #339933;">=</span><span style="color: #CC0000;">220</span><span style="color: #339933;">;</span>
        <span style="color: #003366; font-weight: bold;">var</span> bandInfos <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span>
          Timeline.<span style="color: #660066;">createBandInfo</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
              width<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;20%&quot;</span><span style="color: #339933;">,</span>
              intervalUnit<span style="color: #339933;">:</span> Timeline.<span style="color: #660066;">DateTime</span>.<span style="color: #660066;">DAY</span><span style="color: #339933;">,</span>
              intervalPixels<span style="color: #339933;">:</span> <span style="color: #CC0000;">100</span><span style="color: #339933;">,</span>
              eventSource<span style="color: #339933;">:</span> eventSource<span style="color: #339933;">,</span>
              theme<span style="color: #339933;">:</span>theme
          <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
          Timeline.<span style="color: #660066;">createBandInfo</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
              width<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;50%&quot;</span><span style="color: #339933;">,</span>
              intervalUnit<span style="color: #339933;">:</span> Timeline.<span style="color: #660066;">DateTime</span>.<span style="color: #660066;">MONTH</span><span style="color: #339933;">,</span>
              intervalPixels<span style="color: #339933;">:</span> <span style="color: #CC0000;">100</span><span style="color: #339933;">,</span>
              eventSource<span style="color: #339933;">:</span> eventSource<span style="color: #339933;">,</span>
              theme<span style="color: #339933;">:</span>theme
          <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
          Timeline.<span style="color: #660066;">createBandInfo</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
              width<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;30%&quot;</span><span style="color: #339933;">,</span>
              intervalUnit<span style="color: #339933;">:</span> Timeline.<span style="color: #660066;">DateTime</span>.<span style="color: #660066;">YEAR</span><span style="color: #339933;">,</span>
              intervalPixels<span style="color: #339933;">:</span> <span style="color: #CC0000;">200</span><span style="color: #339933;">,</span>
              eventSource<span style="color: #339933;">:</span> eventSource<span style="color: #339933;">,</span>
              theme<span style="color: #339933;">:</span>theme
          <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
        bandInfos<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#93;</span>.<span style="color: #660066;">syncWith</span> <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span>
        bandInfos<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">2</span><span style="color: #009900;">&#93;</span>.<span style="color: #660066;">syncWith</span> <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span>
        bandInfos<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">2</span><span style="color: #009900;">&#93;</span>.<span style="color: #660066;">highlight</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">;</span>
        tl <span style="color: #339933;">=</span> Timeline.<span style="color: #660066;">create</span><span style="color: #009900;">&#40;</span>document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;timeline&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> bandInfos<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        eventSource.<span style="color: #660066;">loadJSON</span><span style="color: #009900;">&#40;</span>events<span style="color: #339933;">,</span> <span style="color: #3366CC;">''</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>
      <span style="color: #003366; font-weight: bold;">var</span> resizeTimerID <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">null</span><span style="color: #339933;">;</span>
      <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #000066;">onResize</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
          <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>resizeTimerID <span style="color: #339933;">==</span> <span style="color: #003366; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
              resizeTimerID <span style="color: #339933;">=</span> window.<span style="color: #660066;">setTimeout</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                  resizeTimerID <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">null</span><span style="color: #339933;">;</span>
                  tl.<span style="color: #660066;">layout</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
              <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">500</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
          <span style="color: #009900;">&#125;</span>
      <span style="color: #009900;">&#125;</span>
    <span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span>
  <span style="color: #339933;">&lt;%</span> end <span style="color: #339933;">%&gt;</span></pre></div></div>

<p><strong>Things that you should take note of:</strong></p>
<ul>
<li>I used Ruby&#8217;s DateTime iso8601 message to help pass a date that Timeline could understand.</li>
<li>I called <strong>eventSource.loadJSON(events, &#8221;);</strong> where I passed in the events JSON array.</li>
</ul>
<p>Hopefully, these two pointers can help you save some time integrating Timeline into your project!  Since this is on my blog, feel totally free to take/use/steal/distribute/copy/modify any code you see fit. All I ask is if you find any bugs, have any comments, or can think of ways to make my ugly code cleaner &#8211; Iâ€™d love to hear from you. <img src='http://blog.localkinegrinds.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<h2>Enjoy!</h2>
<img src="http://blog.localkinegrinds.com/?ak_action=api_record_view&id=142&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://blog.localkinegrinds.com/2007/11/06/installing-mit-similes-timeline-locally-w-rails-integration/feed/</wfw:commentRss>
		<slash:comments>30</slash:comments>
		</item>
	</channel>
</rss>
