<?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>Darian Shimy &#187; rails</title>
	<atom:link href="http://www.darianshimy.com/tag/rails/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.darianshimy.com</link>
	<description></description>
	<lastBuildDate>Sat, 01 Oct 2011 06:06:15 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>SQL Logging to script/console</title>
		<link>http://www.darianshimy.com/2009/10/sql-logging-to-scriptconsole/</link>
		<comments>http://www.darianshimy.com/2009/10/sql-logging-to-scriptconsole/#comments</comments>
		<pubDate>Sun, 11 Oct 2009 04:37:06 +0000</pubDate>
		<dc:creator>Darian Shimy</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[console]]></category>
		<category><![CDATA[hirb]]></category>
		<category><![CDATA[irb]]></category>
		<category><![CDATA[rails]]></category>

		<guid isPermaLink="false">http://www.darianshimy.com/?p=437</guid>
		<description><![CDATA[When running a Rails console session, a true time saver is directing the ActiveRecord logs to STDOUT instead of the log file.  This is easily accomplished adding the following to your ~/.irbrc file: if rails_env = ENV&#91;'RAILS_ENV'&#93; # Called after &#8230; <a href="http://www.darianshimy.com/2009/10/sql-logging-to-scriptconsole/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>When running a Rails console session, a true time saver is directing the ActiveRecord logs to STDOUT instead of the log file.  This is easily accomplished adding the following to your ~/.irbrc file:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">if</span> rails_env = ENV<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'RAILS_ENV'</span><span style="color:#006600; font-weight:bold;">&#93;</span>
  <span style="color:#008000; font-style:italic;"># Called after the irb session is initialized and Rails has</span>
  <span style="color:#008000; font-style:italic;"># been loaded (props: Mike Clark).</span>
  IRB.<span style="color:#9900CC;">conf</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:IRB_RC</span><span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#CC0066; font-weight:bold;">Proc</span>.<span style="color:#9900CC;">new</span> <span style="color:#9966CC; font-weight:bold;">do</span>
    <span style="color:#6666ff; font-weight:bold;">ActiveRecord::Base</span>.<span style="color:#9900CC;">logger</span> = <span style="color:#CC00FF; font-weight:bold;">Logger</span>.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span>STDOUT<span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#6666ff; font-weight:bold;">ActiveRecord::Base</span>.<span style="color:#9900CC;">instance_eval</span> <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#9966CC; font-weight:bold;">alias</span> :<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#ff3333; font-weight:bold;">:find</span> <span style="color:#006600; font-weight:bold;">&#125;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>If someone knows the original author of these lines, let me know and I&#8217;ll give them proper attribution.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.darianshimy.com/2009/10/sql-logging-to-scriptconsole/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Error Handling with XML and Authlogic</title>
		<link>http://www.darianshimy.com/2009/10/error-handling-with-xml-and-authlogic/</link>
		<comments>http://www.darianshimy.com/2009/10/error-handling-with-xml-and-authlogic/#comments</comments>
		<pubDate>Sat, 10 Oct 2009 07:12:23 +0000</pubDate>
		<dc:creator>Darian Shimy</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[authlogic]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://www.darianshimy.com/?p=427</guid>
		<description><![CDATA[I was helping a friend integrate an API into the application. He is running Rails 2.3.4 with Authlogic. His authentication check method was the following: 1 2 3 4 5 6 7 8 def require_user unless current_user session&#91;:return_to&#93; = request.request_uri &#8230; <a href="http://www.darianshimy.com/2009/10/error-handling-with-xml-and-authlogic/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I was helping a friend integrate an API into the application.  He is running <a href="http://rubyonrails.org/">Rails 2.3.4</a> with <a href="http://github.com/binarylogic/authlogic">Authlogic</a>.  His authentication check method was the following:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">def</span> require_user
  <span style="color:#9966CC; font-weight:bold;">unless</span> current_user
    session<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:return_to</span><span style="color:#006600; font-weight:bold;">&#93;</span> = request.<span style="color:#9900CC;">request_uri</span>
    flash<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:notice</span><span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#996600;">&quot;You must be logged in to access this page&quot;</span>
    redirect_to new_user_session_url
    <span style="color:#0000FF; font-weight:bold;">return</span> <span style="color:#0000FF; font-weight:bold;">false</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></td></tr></table></div>

<p>Although this worked great for the HTML requests, the XML requests were getting HTML response with a redirect to the login page.  Not what we were looking for.  Instead, the require_user method needed to be aware of the mime-type and return an appropriate response.</p>
<p>Here is the block that responds to the mime-type.  Instead of getting an HTML response to an XML request, an XML error reponse with the correct HTTP status code is returned.</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
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">def</span> require_user
  <span style="color:#9966CC; font-weight:bold;">unless</span> current_user
    respond_to <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>format<span style="color:#006600; font-weight:bold;">|</span>
      <span style="color:#CC0066; font-weight:bold;">format</span>.<span style="color:#9900CC;">html</span> <span style="color:#006600; font-weight:bold;">&#123;</span>
        session<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:return_to</span><span style="color:#006600; font-weight:bold;">&#93;</span> = request.<span style="color:#9900CC;">request_uri</span>
        flash<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:notice</span><span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#996600;">&quot;You must be logged in to access this page&quot;</span>
        redirect_to new_user_session_url
      <span style="color:#006600; font-weight:bold;">&#125;</span>
      <span style="color:#CC0066; font-weight:bold;">format</span>.<span style="color:#9900CC;">xml</span> <span style="color:#006600; font-weight:bold;">&#123;</span>
        user = User.<span style="color:#9900CC;">new</span>
        user.<span style="color:#9900CC;">errors</span>.<span style="color:#9900CC;">add_to_base</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;Authentication is required.&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
        render <span style="color:#ff3333; font-weight:bold;">:xml</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> user.<span style="color:#9900CC;">errors</span>, <span style="color:#ff3333; font-weight:bold;">:status</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">401</span>
      <span style="color:#006600; font-weight:bold;">&#125;</span>
      <span style="color:#9966CC; font-weight:bold;">end</span>
    <span style="color:#0000FF; font-weight:bold;">return</span> <span style="color:#0000FF; font-weight:bold;">false</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.darianshimy.com/2009/10/error-handling-with-xml-and-authlogic/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Capistrano &#8211; Deploying a Branch</title>
		<link>http://www.darianshimy.com/2009/10/capistrano-deploying-a-branch/</link>
		<comments>http://www.darianshimy.com/2009/10/capistrano-deploying-a-branch/#comments</comments>
		<pubDate>Thu, 08 Oct 2009 14:00:00 +0000</pubDate>
		<dc:creator>Darian Shimy</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[branch]]></category>
		<category><![CDATA[capistrano]]></category>
		<category><![CDATA[deployment]]></category>
		<category><![CDATA[git]]></category>
		<category><![CDATA[rails]]></category>

		<guid isPermaLink="false">http://www.darianshimy.com/?p=410</guid>
		<description><![CDATA[When deploying from Capistrano, I like to have the following in my &#8216;deploy.rb&#8217; file: set :scm, &#34;git&#34; set :repository, &#34;git@www.example.com:project.git&#34; set :git_shallow_clone, 1 set :deploy_via, :remote_cache This allows speeds deployments by keeping a versions checked out on the server in &#8230; <a href="http://www.darianshimy.com/2009/10/capistrano-deploying-a-branch/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>When deploying from <a href="http://www.capify.org">Capistrano</a>, I like to have the following in my &#8216;deploy.rb&#8217; file:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">set <span style="color:#ff3333; font-weight:bold;">:scm</span>, <span style="color:#996600;">&quot;git&quot;</span>
set <span style="color:#ff3333; font-weight:bold;">:repository</span>, <span style="color:#996600;">&quot;git@www.example.com:project.git&quot;</span>
set <span style="color:#ff3333; font-weight:bold;">:git_shallow_clone</span>, <span style="color:#006666;">1</span>
set <span style="color:#ff3333; font-weight:bold;">:deploy_via</span>, <span style="color:#ff3333; font-weight:bold;">:remote_cache</span></pre></div></div>

<p>This allows speeds deployments by keeping a versions checked out on the server in &#8216;shared/cached-copy&#8217;.  When it comes to deploying, it is always best to deploy from a branch instead of the master/head/trunk.  To handle this, add the following:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">set <span style="color:#ff3333; font-weight:bold;">:branch</span>, fetch<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:branch</span>, “master”<span style="color:#006600; font-weight:bold;">&#41;</span></pre></div></div>

<p>When you deploy, run the following:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ cap deploy <span style="color: #660033;">-S</span> <span style="color: #007800;">branch</span>=REL_1.0</pre></div></div>

<p>If you don&#8217;t specify the branch, the master is used.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.darianshimy.com/2009/10/capistrano-deploying-a-branch/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Capistrano &#8211; Email on Deployment</title>
		<link>http://www.darianshimy.com/2009/10/capistrano-email-on-deployment/</link>
		<comments>http://www.darianshimy.com/2009/10/capistrano-email-on-deployment/#comments</comments>
		<pubDate>Wed, 07 Oct 2009 14:00:12 +0000</pubDate>
		<dc:creator>Darian Shimy</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[capistrano]]></category>
		<category><![CDATA[deployment]]></category>
		<category><![CDATA[rails]]></category>

		<guid isPermaLink="false">http://www.darianshimy.com/?p=404</guid>
		<description><![CDATA[It&#8217;s a good practice to send a notification to certain people when a new version is deployed. This process can easily be automated in Capistrano. Add the following file to the &#8216;lib&#8217; directory with the filename &#8216;cap_mailer.rb&#8217;: 1 2 3 &#8230; <a href="http://www.darianshimy.com/2009/10/capistrano-email-on-deployment/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s a good practice to send a notification to certain people when a new version is deployed.  This process can easily be automated in <a href="http://www.capify.org">Capistrano</a>.  Add the following file to the &#8216;lib&#8217; directory with the filename &#8216;cap_mailer.rb&#8217;:</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
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'rubygems'</span>
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'actionmailer'</span>
&nbsp;
<span style="color:#6666ff; font-weight:bold;">ActionMailer::Base</span>.<span style="color:#9900CC;">smtp_settings</span> = <span style="color:#006600; font-weight:bold;">&#123;</span>:address <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;localhost&quot;</span>, <span style="color:#ff3333; font-weight:bold;">:port</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">25</span>, <span style="color:#ff3333; font-weight:bold;">:domain</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'example.com'</span><span style="color:#006600; font-weight:bold;">&#125;</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">class</span> CapMailer <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#6666ff; font-weight:bold;">ActionMailer::Base</span>
  <span style="color:#9966CC; font-weight:bold;">def</span> deploy_notification<span style="color:#006600; font-weight:bold;">&#40;</span>options<span style="color:#006600; font-weight:bold;">&#41;</span>    
    message = <span style="color:#996600;">&quot;Deployment<span style="color:#000099;">\n</span><span style="color:#000099;">\n</span>&quot;</span>
    options.<span style="color:#9900CC;">each_pair</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>k,v<span style="color:#006600; font-weight:bold;">|</span>
      message <span style="color:#006600; font-weight:bold;">&lt;&lt;</span> <span style="color:#996600;">&quot;  #{k}: #{v}<span style="color:#000099;">\n</span>&quot;</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
    recipients <span style="color:#996600;">&quot;notify-deployment@example.com&quot;</span>
    from       <span style="color:#996600;">'noreply@example.com'</span>
    subject    <span style="color:#996600;">&quot;Deployment to #{options[:rails_env]}&quot;</span>
    body       message
  <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;">module</span> CapistranoMailer
  <span style="color:#9966CC; font-weight:bold;">def</span> send<span style="color:#006600; font-weight:bold;">&#40;</span>options<span style="color:#006600; font-weight:bold;">&#41;</span>
    CapMailer.<span style="color:#9900CC;">deliver_deploy_notification</span><span style="color:#006600; font-weight:bold;">&#40;</span>options<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;
Capistrano.<span style="color:#9900CC;">plugin</span> <span style="color:#ff3333; font-weight:bold;">:mailer</span>, CapistranoMailer</pre></td></tr></table></div>

<p>In the &#8216;deploy.rb&#8217; file, add the following:</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
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'lib/cap_mailer'</span>
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'etc'</span>
&nbsp;
namespace <span style="color:#ff3333; font-weight:bold;">:deploy</span> <span style="color:#9966CC; font-weight:bold;">do</span>
  desc <span style="color:#996600;">&quot;Sends an email upon successful deployment&quot;</span>
  task <span style="color:#ff3333; font-weight:bold;">:notify</span> <span style="color:#9966CC; font-weight:bold;">do</span>
    mailer.<span style="color:#9900CC;">send</span><span style="color:#006600; font-weight:bold;">&#40;</span>
      <span style="color:#ff3333; font-weight:bold;">:rails_env</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> rails_env,
      <span style="color:#ff3333; font-weight:bold;">:deploy_to</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> deploy_to,
      <span style="color:#ff3333; font-weight:bold;">:branch</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> branch,
      <span style="color:#ff3333; font-weight:bold;">:application</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> application,
      <span style="color:#ff3333; font-weight:bold;">:repository</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> repository,
      <span style="color:#ff3333; font-weight:bold;">:deployment_time</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#CC00FF; font-weight:bold;">Time</span>.<span style="color:#9900CC;">new</span>.<span style="color:#9900CC;">to_s</span>,
      <span style="color:#ff3333; font-weight:bold;">:deployer_username</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> Etc.<span style="color:#9900CC;">getlogin</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;
after <span style="color:#996600;">&quot;deploy&quot;</span>, <span style="color:#996600;">&quot;deploy:notify&quot;</span>
after <span style="color:#996600;">&quot;deploy:migrations&quot;</span>, <span style="color:#996600;">&quot;deploy:notify&quot;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.darianshimy.com/2009/10/capistrano-email-on-deployment/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Capistrano &#8211; Install Gems Remotely</title>
		<link>http://www.darianshimy.com/2009/10/capistrano-install-gems-remotely/</link>
		<comments>http://www.darianshimy.com/2009/10/capistrano-install-gems-remotely/#comments</comments>
		<pubDate>Tue, 06 Oct 2009 14:00:49 +0000</pubDate>
		<dc:creator>Darian Shimy</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[capistrano]]></category>
		<category><![CDATA[deployment]]></category>
		<category><![CDATA[gems]]></category>
		<category><![CDATA[rails]]></category>

		<guid isPermaLink="false">http://www.darianshimy.com/?p=401</guid>
		<description><![CDATA[Capistrano does not have out-of-the-box support for installing gems on your servers. You may not need this if you are packing them, but some of us would like to run the equivalent of &#8216;rake gems:install&#8217;. To do this in capistrano, &#8230; <a href="http://www.darianshimy.com/2009/10/capistrano-install-gems-remotely/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.capify.org">Capistrano</a> does not have out-of-the-box support for installing gems on your servers.  You may not need this if you are packing them, but some of us would like to run the equivalent of &#8216;rake gems:install&#8217;.  To do this in capistrano, add the following to your deploy.rb file:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">namespace <span style="color:#ff3333; font-weight:bold;">:gems</span> <span style="color:#9966CC; font-weight:bold;">do</span>
  desc <span style="color:#996600;">&quot;Install gems&quot;</span>
  task <span style="color:#ff3333; font-weight:bold;">:install</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>
    run <span style="color:#996600;">&quot;cd #{current_release} &amp;&amp; #{sudo} rake RAILS_ENV=#{rails_env} gems:install&quot;</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://www.darianshimy.com/2009/10/capistrano-install-gems-remotely/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Capistrano &#8211; Adding Help to Deployments</title>
		<link>http://www.darianshimy.com/2009/10/capistrano-adding-help-to-deployments/</link>
		<comments>http://www.darianshimy.com/2009/10/capistrano-adding-help-to-deployments/#comments</comments>
		<pubDate>Mon, 05 Oct 2009 14:00:05 +0000</pubDate>
		<dc:creator>Darian Shimy</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[capistrano]]></category>
		<category><![CDATA[deployment]]></category>
		<category><![CDATA[rails]]></category>

		<guid isPermaLink="false">http://www.darianshimy.com/?p=397</guid>
		<description><![CDATA[If you don&#8217;t do something everyday, you tend to forget how to do it. The same is with the deployments. To help this, you can easily add a help section to Capistrano in your &#8216;config/deploy.rb&#8217; file. Here is a sample: &#8230; <a href="http://www.darianshimy.com/2009/10/capistrano-adding-help-to-deployments/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>If you don&#8217;t do something everyday, you tend to forget how to do it.  The same is with the deployments.  To help this, you can easily add a help section to Capistrano in your &#8216;config/deploy.rb&#8217; file.  Here is a sample:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">desc <span style="color:#996600;">&quot;Print usage/help information&quot;</span>
task <span style="color:#ff3333; font-weight:bold;">:help</span> <span style="color:#9966CC; font-weight:bold;">do</span>
    <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;Usage: cap &lt;task&gt; -S stage=[staging|production] -S branch=&lt;branch_name&gt;&quot;</span>
    <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;&quot;</span>
    <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;Examples:&quot;</span>
    <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;----------------------------------------------------------------------&quot;</span>
    <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;  Production:&quot;</span>
    <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;    $ cap deploy:migrations -S stage=production&quot;</span>
    <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;&quot;</span>
    <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;  Staging:&quot;</span>
    <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;    $ cap deploy:migrations&quot;</span>
    <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;&quot;</span>
    <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;  Production with branch:&quot;</span>
    <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;    $ cap deploy:migrations -S stage=production -S branch=rel_001&quot;</span>
    <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;&quot;</span>
    <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;  Staging with branch:&quot;</span>
    <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;    $ cap deploy:migrations -S branch=rel_001&quot;</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>When you forget how to do something, just run the following:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ cap <span style="color: #7a0874; font-weight: bold;">help</span>
&nbsp;
Usage: cap <span style="color: #000000; font-weight: bold;">&lt;</span>task<span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #660033;">-S</span> <span style="color: #007800;">stage</span>=<span style="color: #7a0874; font-weight: bold;">&#91;</span>staging<span style="color: #000000; font-weight: bold;">|</span>production<span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #660033;">-S</span> <span style="color: #007800;">branch</span>=<span style="color: #000000; font-weight: bold;">&lt;</span>branch_name<span style="color: #000000; font-weight: bold;">&gt;</span>
  <span style="color: #000000; font-weight: bold;">*</span> executing <span style="color: #000000; font-weight: bold;">`</span><span style="color: #7a0874; font-weight: bold;">help</span><span style="color: #ff0000;">'
Examples:
----------------------------------------------------------------------
  Production:
    $ cap deploy:migrations -S stage=production
&nbsp;
  Staging:
    $ cap deploy:migrations
&nbsp;
  Production with branch:
    $ cap deploy:migrations -S stage=production -S branch=rel_001
&nbsp;
  Staging with branch:
    $ cap deploy:migrations -S branch=rel_001</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.darianshimy.com/2009/10/capistrano-adding-help-to-deployments/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Capistrano &#8211; Multiple Environments</title>
		<link>http://www.darianshimy.com/2009/10/capistrano-multiple-environments/</link>
		<comments>http://www.darianshimy.com/2009/10/capistrano-multiple-environments/#comments</comments>
		<pubDate>Fri, 02 Oct 2009 20:55:27 +0000</pubDate>
		<dc:creator>Darian Shimy</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[capistrano]]></category>
		<category><![CDATA[deployment]]></category>
		<category><![CDATA[rails]]></category>

		<guid isPermaLink="false">http://www.darianshimy.com/?p=365</guid>
		<description><![CDATA[Capistrano is designed to deploy your Rails application (yes it can handle others, but more work is required) to production.  However, most applications need to be deployed to more than one environment.  For example, we deploy to a staging environment &#8230; <a href="http://www.darianshimy.com/2009/10/capistrano-multiple-environments/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.capify.org/index.php/Capistrano">Capistrano</a> is designed to deploy your Rails application (yes it can handle others, but more work is required) to production.  However, most applications need to be deployed to more than one environment.  For example, we deploy to a staging environment in addition to production.  This lets select users and internal employees kick the tires before we release it in the wild.  After many <a href="http://weblog.jamisbuck.org/2007/7/23/capistrano-multistage">complaints</a>, <a href="http://github.com/jamis/capistrano-ext">capistrano-ext</a> was born.  I am all in favor of using plug ins, but this is such a trivial issue, it&#8217;s easier to add the code than worry about the plugin.</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">set <span style="color:#ff3333; font-weight:bold;">:stage</span>, <span style="color:#996600;">&quot;staging&quot;</span> <span style="color:#9966CC; font-weight:bold;">unless</span> variables<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:stage</span><span style="color:#006600; font-weight:bold;">&#93;</span>
set <span style="color:#ff3333; font-weight:bold;">:deploy_to</span>, <span style="color:#996600;">&quot;/var/www/#{application}&quot;</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">case</span> stage
<span style="color:#9966CC; font-weight:bold;">when</span> <span style="color:#996600;">&quot;staging&quot;</span>
  set <span style="color:#ff3333; font-weight:bold;">:rails_env</span>, <span style="color:#996600;">&quot;staging&quot;</span>
  role <span style="color:#ff3333; font-weight:bold;">:web</span>, <span style="color:#996600;">&quot;staging.example.com&quot;</span>
  role <span style="color:#ff3333; font-weight:bold;">:app</span>, <span style="color:#996600;">&quot;staging.example.com&quot;</span>
  role <span style="color:#ff3333; font-weight:bold;">:db</span>,  <span style="color:#996600;">&quot;staging.example.com&quot;</span>, <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>
<span style="color:#9966CC; font-weight:bold;">when</span> <span style="color:#996600;">&quot;production&quot;</span>
  set <span style="color:#ff3333; font-weight:bold;">:rails_env</span>, <span style="color:#996600;">&quot;production&quot;</span>
  role <span style="color:#ff3333; font-weight:bold;">:web</span>, <span style="color:#996600;">&quot;production.example.com&quot;</span>
  role <span style="color:#ff3333; font-weight:bold;">:app</span>, <span style="color:#996600;">&quot;production.example.com&quot;</span>
  role <span style="color:#ff3333; font-weight:bold;">:db</span>,  <span style="color:#996600;">&quot;production.example.com&quot;</span>, <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>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>To deploy to the correct environment call capistrano:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ cap deploy <span style="color: #660033;">-S</span> <span style="color: #007800;">stage</span>=staging</pre></div></div>

<p>If your staging and production share the same machine (not the best idea):</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">set <span style="color:#ff3333; font-weight:bold;">:stage</span>, <span style="color:#996600;">&quot;staging&quot;</span> <span style="color:#9966CC; font-weight:bold;">unless</span> variables<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:stage</span><span style="color:#006600; font-weight:bold;">&#93;</span>
server <span style="color:#996600;">&quot;example.com&quot;</span>, <span style="color:#ff3333; font-weight:bold;">:app</span>, <span style="color:#ff3333; font-weight:bold;">:web</span>: db
&nbsp;
<span style="color:#9966CC; font-weight:bold;">case</span> stage
<span style="color:#9966CC; font-weight:bold;">when</span> <span style="color:#996600;">&quot;staging&quot;</span>
  set <span style="color:#ff3333; font-weight:bold;">:rails_env</span>, <span style="color:#996600;">&quot;staging&quot;</span>
  set <span style="color:#ff3333; font-weight:bold;">:deploy_to</span>, <span style="color:#996600;">&quot;/var/www/staging-#{application}&quot;</span>
<span style="color:#9966CC; font-weight:bold;">when</span> <span style="color:#996600;">&quot;production&quot;</span>
  set <span style="color:#ff3333; font-weight:bold;">:rails_env</span>, <span style="color:#996600;">&quot;production&quot;</span>
  set <span style="color:#ff3333; font-weight:bold;">:deploy_to</span>, <span style="color:#996600;">&quot;/var/www/production-#{application}&quot;</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.darianshimy.com/2009/10/capistrano-multiple-environments/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Update: Fixing Rails in Snow Leopard</title>
		<link>http://www.darianshimy.com/2009/09/fixing-rails-in-snow-leopard/</link>
		<comments>http://www.darianshimy.com/2009/09/fixing-rails-in-snow-leopard/#comments</comments>
		<pubDate>Fri, 04 Sep 2009 05:27:12 +0000</pubDate>
		<dc:creator>Darian Shimy</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[fail]]></category>
		<category><![CDATA[mac ports]]></category>
		<category><![CDATA[mongrel]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[os x]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[snow leopard]]></category>
		<category><![CDATA[thin]]></category>

		<guid isPermaLink="false">http://www.darianshimy.com/?p=256</guid>
		<description><![CDATA[I was too quick to declare success in my update to Snow Leopard earlier this week.  As it turns out, much of my recovered space came from Xcode being uninstalled.  Easy fix.  Grabbed the DVD and installed it in a &#8230; <a href="http://www.darianshimy.com/2009/09/fixing-rails-in-snow-leopard/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I was too quick to declare success in my update to Snow Leopard earlier <a href="http://www.darianshimy.com/2009/09/snow-leopard-upgrade/">this week</a>.  As it turns out, much of my recovered space came from <a href="http://developer.apple.com/TOOLS/Xcode/">Xcode</a> being uninstalled.  Easy fix.  Grabbed the DVD and installed it in a few minutes.  After doing some deeper checking, I found anything with native extensions or compiled with Leopard was not working.  Thanks for the heads up Apple.</p>
<p>With the move to 64 bit, my older 32-bit version of MySQL was moved to /usr/local/mysql-5.0.45-osx10.4-i686.  Grabbed the <a href="http://dev.mysql.com/downloads/mysql/5.1.html#macosx-dmg">latest</a> and installed the 64-bit version.  You may want to skip the preferences pane since it runs in 32-bit and causes the System Preferences to reload each time.</p>
<p><a href="http://www.macports.org/">Macports</a> needed a fresh install as well.  After that I needed to clean out the old builds with:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> port <span style="color: #660033;">-f</span> uninstall installed</pre></div></div>

<p>This wiped everything out and I needed to reinstall my ports.  As expected my gems were in need of help as well.  Although most were resolved with the following:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> gem update</pre></div></div>

<p>the MySQL gem needed some help finding it&#8217;s cousins:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">env</span> <span style="color: #007800;">ARCHFLAGS</span>=<span style="color: #ff0000;">&quot;-arch x86_64&quot;</span> gem <span style="color: #c20cb9; font-weight: bold;">install</span> mysql <span style="color: #660033;">--</span> <span style="color: #660033;">--with-mysql-config</span>=<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>mysql<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>mysql_config</pre></div></div>

<p>Finally, Mongrel decided to hang during the startup and WEBrick as no better.  Had to grab <a href="http://code.macournoyer.com/thin/">Thin</a>.  Worked like a champ.  Note to self: need to switch to Passenger for development.</p>
<p>I&#8217;m sure I&#8217;m missing a few things, but right now, most things seem to be working.  I&#8217;ll update this post if I find anything else.</p>
<p><strong>Update:</strong> Mongrel can be fixed by uninstalling mongrel and fast thread and reinstalling mongrel:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> gem uninstall mongrel fastthread
$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> gem <span style="color: #c20cb9; font-weight: bold;">install</span> mongrel</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.darianshimy.com/2009/09/fixing-rails-in-snow-leopard/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Capistrano is Fixed in Snow Leopard</title>
		<link>http://www.darianshimy.com/2009/09/capistrano-is-fixed-in-snow-leopard/</link>
		<comments>http://www.darianshimy.com/2009/09/capistrano-is-fixed-in-snow-leopard/#comments</comments>
		<pubDate>Fri, 04 Sep 2009 03:20:03 +0000</pubDate>
		<dc:creator>Darian Shimy</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[capistrano]]></category>
		<category><![CDATA[fail]]></category>
		<category><![CDATA[os x]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[snow leopard]]></category>

		<guid isPermaLink="false">http://www.darianshimy.com/?p=249</guid>
		<description><![CDATA[There were a number of things that seemed to break with the upgrade to Snow Leopard.  The latest is my ability to deploy Rails application using Capistrano.  For some reason, the SSH connection would hang.  Looks like this was fixed &#8230; <a href="http://www.darianshimy.com/2009/09/capistrano-is-fixed-in-snow-leopard/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>There were a number of things that seemed to break with the upgrade to Snow Leopard.  The latest is my ability to deploy Rails application using Capistrano.  For some reason, the SSH connection would hang.  Looks like this was fixed today with the 2.0.15 release of <a href="http://github.com/net-ssh/net-ssh/blob/92a213629fb11f624c4624464759e4d82c5028b6/CHANGELOG.rdoc">net-ssh</a>.</p>
<p>To get things working again, just update net-ssh:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> gem update net-ssh
Updating installed gems
Updating net-ssh
Successfully installed net-ssh-2.0.15
Gems updated: net-ssh</pre></div></div>

<p>Deployments work like a charm.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.darianshimy.com/2009/09/capistrano-is-fixed-in-snow-leopard/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

