<?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>Lasse Bunk&#039;s weblog &#187; Capistrano</title>
	<atom:link href="http://lassebunk.dk/tag/capistrano/feed/" rel="self" type="application/rss+xml" />
	<link>http://lassebunk.dk</link>
	<description>Ruby on Rails, programming, and SEO</description>
	<lastBuildDate>Sat, 19 May 2012 10:18:29 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Getting your assets to work when upgrading to Rails 3.1</title>
		<link>http://lassebunk.dk/2011/09/03/getting-your-assets-to-work-when-upgrading-to-rails-3-1/</link>
		<comments>http://lassebunk.dk/2011/09/03/getting-your-assets-to-work-when-upgrading-to-rails-3-1/#comments</comments>
		<pubDate>Sat, 03 Sep 2011 17:39:12 +0000</pubDate>
		<dc:creator>lassebunk</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[Assets]]></category>
		<category><![CDATA[Capistrano]]></category>
		<category><![CDATA[Deployment]]></category>

		<guid isPermaLink="false">http://lassebunk.dk/?p=1720</guid>
		<description><![CDATA[How to get the new Rails 3.1 assets pipeline working when upgrading or migrating from a Rails 3.0 app.]]></description>
			<content:encoded><![CDATA[<p>I was upgrading an app from Rails 3.0 to Rails 3.1 and had some trouble when it came to assets. Here&#8217;s how I got it to work.</p>
<h3>1. Upgrading to Rails 3.1</h3>
<p>Add Rails 3.1 to your Gemfile. Add or change the <code>gem 'rails'</code> line:</p>
<pre class="brush: ruby; title: ; notranslate">
gem 'rails', '3.1.0'
</pre>
<p>Bundle install:</p>
<pre class="brush: bash; title: ; notranslate">
$ bundle install
</pre>
<p>Run the update task to get your Rails files up to date, but beware! Just overwriting all files will probably mess up your app, so make sure to backup files or take notice of what changes you need to add to the new files before overwriting them. It will ask you what to do:</p>
<pre class="brush: bash; title: ; notranslate">
$ rake rails:update
</pre>
<p>Now your app should be running Rails 3.1. You can try running it using <code>rails s</code> but it probably won&#8217;t look great because we&#8217;ve not yet migrated the assets.</p>
<h3>2. Migrating your assets</h3>
<p>Try switching off the assets pipeline by commenting out the following line in <code>config/application.rb</code>:</p>
<pre class="brush: ruby; title: ; notranslate">
# config.assets.enabled = true
</pre>
<p>Your app should now be running as usual. If it doesn&#8217;t, try ironing out any issues before switching on the assets again:</p>
<pre class="brush: ruby; title: ; notranslate">
config.assets.enabled = true
</pre>
<p>We&#8217;re now ready to migrate the assets.</p>
<p>First, add this to your <code>Gemfile</code>:</p>
<pre class="brush: ruby; title: ; notranslate">
gem 'jquery-rails'
group :assets do
  gem 'sass-rails', &quot;  ~&gt; 3.1.0&quot;
  gem 'coffee-rails', &quot;~&gt; 3.1.0&quot;
  gem 'uglifier'
end
</pre>
<p>And install:</p>
<pre class="brush: bash; title: ; notranslate">
$ bundle install
</pre>
<p>Now to the actual migration:</p>
<ol>
<li>Make sure you have the <code>images</code>, <code>javascripts</code>, and <code>stylesheets</code> folders in your <code>app/assets</code> folder.</li>
<li>Move all content from <code>public/images</code> into <code>app/assets/images</code>.</li>
<li>Move all content from <code>public/javascripts</code> into <code>app/assets/javascripts</code>.</li>
<li>Move all content from <code>public/stylesheets</code> into <code>app/assets/stylesheets</code>.</li>
</ol>
<p>Your javascripts and stylesheets will be compiled into a single <code>application.js</code> and <code>application.css</code>, so add or change this in your <code>app/views/layouts/application.html.erb</code>:</p>
<pre class="brush: ruby; title: ; notranslate">
&lt;%= stylesheet_link_tag 'application' %&gt;
&lt;%= javascript_include_tag 'application' %&gt;
</pre>
<p>To make sure that the assets generator will find all your javascripts and stylesheets, we will include all your javascripts in <code>application.js</code> and all your stylesheets in <code>application.css</code>. Assuming you are using jQuery, you can delete <code>jquery.js</code> and <code>jquery-ui.js</code> as they will be required and inserted automatically. Add the following to the top of <code>app/assets/javascripts/application.js</code>:</p>
<pre class="brush: jscript; title: ; notranslate">
//= require jquery
//= require jquery_ujs
//= require_tree .
</pre>
<p>And to the top of <code>app/assets/stylesheets/application.css</code>:</p>
<pre class="brush: css; title: ; notranslate">
/*
 *= require_self
 *= require_tree .
*/
</pre>
<p>Your javascripts and stylesheets will now be included automatically.</p>
<p>At last update all your image paths from <code>/images</code> to <code>/assets</code>. If you&#8217;re using the <code>image_tag</code> helper, all paths will be updated automatically.</p>
<h3>3. Deploying your assets</h3>
<p>Assuming you are deploying using <a href="https://github.com/capistrano/capistrano">Capistrano</a>, add the following to your <code>config/deploy.rb</code>:</p>
<pre class="brush: ruby; title: ; notranslate">
before &quot;deploy:symlink&quot;, &quot;assets:precompile&quot;

namespace :assets do
  desc &quot;Compile assets&quot;
  task :precompile, :roles =&gt; :app do
    run &quot;cd #{release_path} &amp;&amp; rake RAILS_ENV=#{rails_env} assets:precompile&quot;
  end
end
</pre>
<p>Your assets will now be compiled right before your app is moved into place in your production environment.</p>
<p>Try deploying your app:</p>
<pre class="brush: bash; title: ; notranslate">
$ cap deploy
</pre>
<p>If the deployment went as expected, great. If you get an error complaining about a missing JavaScript engine, try adding the following to the <code>assets</code> section of your <code>Gemfile</code>:</p>
<pre class="brush: ruby; title: ; notranslate">
gem 'therubyracer'
</pre>
<p>And run the deployment again.</p>
<p>Your assets should now be in place! If you run into other problems, please write a comment below, and I&#8217;ll see if I can help.</p>
<p>
<a href="http://twitter.com/lassebunk" onclick="abtest.trackGoal(21, this);" class="icon twitter">Follow me on Twitter</a>
</p>]]></content:encoded>
			<wfw:commentRss>http://lassebunk.dk/2011/09/03/getting-your-assets-to-work-when-upgrading-to-rails-3-1/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Rails 3 and Bundler: Deploying gems using Capistrano</title>
		<link>http://lassebunk.dk/2010/09/01/rails-3-bundler-gems-capistrano/</link>
		<comments>http://lassebunk.dk/2010/09/01/rails-3-bundler-gems-capistrano/#comments</comments>
		<pubDate>Wed, 01 Sep 2010 20:17:10 +0000</pubDate>
		<dc:creator>lassebunk</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[Capistrano]]></category>
		<category><![CDATA[Deployment]]></category>
		<category><![CDATA[RubyGems]]></category>

		<guid isPermaLink="false">http://lassebunk.dk/?p=1283</guid>
		<description><![CDATA[How to deploy gems from your Rails 3 application through Capistrano.]]></description>
			<content:encoded><![CDATA[<p>I have previously described how to <a href="http://lassebunk.dk/2009/07/18/deploying-gems-using-capistrano/">deploy gems using Capistrano</a> in a Rails 2 application. After upgrading to Rails 3, this has changed a bit. Rails now uses <a href="http://gembundler.com/">Bundler</a> for dependency management, so we need to use the <code>bundle install</code> command instead of <code>rake gems:install</code>.</p>
<p>In your <code>deploy.rb</code>:</p>
<pre class="brush: ruby; title: ; notranslate">
after &quot;deploy:update_code&quot;, &quot;bundle:install&quot;

namespace :bundle do
  desc &quot;Bundle install&quot;
  task :install, :roles =&gt; :app do
    run &quot;cd #{current_release} &amp;&amp; #{sudo} bundle install&quot;
  end
end
</pre>
<p>It&#8217;s as easy as that. Let me know if you have any comments.</p>
<p>
<a href="http://twitter.com/lassebunk" onclick="abtest.trackGoal(21, this);" class="icon twitter">Follow me on Twitter</a>
</p>]]></content:encoded>
			<wfw:commentRss>http://lassebunk.dk/2010/09/01/rails-3-bundler-gems-capistrano/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Deploying gems using Capistrano</title>
		<link>http://lassebunk.dk/2009/07/18/deploying-gems-using-capistrano/</link>
		<comments>http://lassebunk.dk/2009/07/18/deploying-gems-using-capistrano/#comments</comments>
		<pubDate>Sat, 18 Jul 2009 17:19:32 +0000</pubDate>
		<dc:creator>lassebunk</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[Capistrano]]></category>
		<category><![CDATA[Gems]]></category>
		<category><![CDATA[Rake]]></category>

		<guid isPermaLink="false">http://lassebunk.dk/?p=137</guid>
		<description><![CDATA[How to deploy gems from your Ruby on Rails application through Capistrano.]]></description>
			<content:encoded><![CDATA[<p><strong>Update for Rails 3:</strong> <a href="http://lassebunk.dk/2010/09/01/rails-3-bundler-gems-capistrano/">Rails 3 and Bundler: Deploying gems using Capistrano</a></p>
<p>Thought I&#8217;d share this because I had a lot of trouble figuring out how and where to run the <a href="http://ryandaigle.com/articles/2008/4/1/what-s-new-in-edge-rails-gem-dependencies">&#8220;rake gems:install&#8221;</a> when deploying with <a href="http://www.capify.org">Capistrano</a>. I wanted it to automatically deploy the gems when I call &#8220;cap deploy:migrations&#8221; &#8211; this is done by installing the gems right after update_code, like this:</p>
<pre class="brush: ruby; title: ; notranslate">
# config/deploy.rb
after &quot;deploy:update_code&quot;, &quot;gems:install&quot;

namespace :gems do
  desc &quot;Install gems&quot;
  task :install, :roles =&gt; :app do
    run &quot;cd #{current_release} &amp;&amp; #{sudo} rake gems:install&quot;
  end
end
</pre>
<p>Some of the examples I&#8217;ve seen use &#8220;cd #{current_path}&#8221; but I don&#8217;t think this would work as the &#8220;current&#8221; symlink hasn&#8217;t been updated at the time the &#8220;update_code&#8221; task is run. That&#8217;s why I use &#8220;current_release&#8221;.</p>
<p>Also others use &#8220;rake RAILS_ENV=production gems:install&#8221; but I can&#8217;t see why you should have to use RAILS_ENV here. If I&#8217;m wrong, please correct me.</p>
<p>Some of the links I found when trying to get this to work:</p>
<ul>
<li><a href="http://capitate.rubyforge.org/recipes/deploy.html">Capistrano recipes: deploy</a></li>
<li><a href="http://henrik.nyh.se/2008/10/cap-gems-install-and-a-gem-dependency-gotcha">cap gems:install and a Gem dependency gotcha</a></li>
<li><a href="http://new.teabass.com/posts/install-required-gems-remotely-with-capistrano">Install required gems remotely with capistrano</a></li>
<li><a href="http://github.com/jamis/capistrano/blob/df0935c4c135207582da343aacdd4cf080fcfed0/lib/capistrano/recipes/deploy.rb">lib/capistrano/recipes/deploy.rb</a></li>
</ul>
<p>
<a href="http://twitter.com/lassebunk" onclick="abtest.trackGoal(21, this);" class="icon twitter">Follow me on Twitter</a>
</p>]]></content:encoded>
			<wfw:commentRss>http://lassebunk.dk/2009/07/18/deploying-gems-using-capistrano/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
	</channel>
</rss>

