<?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>Rails vs Whitewater &#187; Github</title>
	<atom:link href="http://justinspowers.com/category/github/feed/" rel="self" type="application/rss+xml" />
	<link>http://justinspowers.com</link>
	<description>Whitewater enthusiast by day, Ruby on Rails programmer by night.</description>
	<lastBuildDate>Sat, 10 Dec 2011 07:42:34 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Rails 3.1 Asset Pipeline automation</title>
		<link>http://justinspowers.com/2011/12/rails-3-1-asset-pipeline-automation/</link>
		<comments>http://justinspowers.com/2011/12/rails-3-1-asset-pipeline-automation/#comments</comments>
		<pubDate>Sat, 10 Dec 2011 07:35:44 +0000</pubDate>
		<dc:creator>Justin</dc:creator>
				<category><![CDATA[Github]]></category>
		<category><![CDATA[Rails]]></category>

		<guid isPermaLink="false">http://justinspowers.com/?p=112</guid>
		<description><![CDATA[I&#8217;ve been spending a lot of time lately working on getting the asset pipeline for my application working. A lot of things weren&#8217;t very clear from the documentation at the time of this writing, so I am going to narrate the process I went through in case anybody else has the same issue. For a [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been spending a lot of time lately working on getting the asset pipeline for my application working. A lot of things weren&#8217;t very clear from the documentation at the time of this writing, so I am going to narrate the process I went through in case anybody else has the same issue.</p>
<p>For a background on the asset pipeline, please read through the <a title="rails guide" href="http://guides.rubyonrails.org/asset_pipeline.html" onclick="pageTracker._trackPageview('/outgoing/guides.rubyonrails.org/asset_pipeline.html?referer=');">rails guide</a> and these two <a title="excellent" href="http://railscasts.com/episodes/279-understanding-the-asset-pipeline" onclick="pageTracker._trackPageview('/outgoing/railscasts.com/episodes/279-understanding-the-asset-pipeline?referer=');">excellent</a> <a title="railscasts" href="http://railscasts.com/episodes/282-upgrading-to-rails-3-1" onclick="pageTracker._trackPageview('/outgoing/railscasts.com/episodes/282-upgrading-to-rails-3-1?referer=');">railscast</a> by Ryan Bates. These got me about 90% of the way there.</p>
<p><span id="more-112"></span>One of the main goals of the asset pipeline is to bundle together all of your application&#8217;s javascript and stylesheets, condense them, and serve them to the end user with a sophisticated caching approach.  This works very well for many of the applications on the web.  In the case of my application, we had several javascript files that were specific to individual pages, and didn&#8217;t play well (for one reason or another) with other areas of the site.  It has long been a requirement that these javascripts are only loaded for these specific pages.  We were accomplishing this by creating a yield section in our application.html.erb like so:<br />
<code>&lt;%= yield :head_includes %&gt;</code><br />
Then, in the pages were we needed to load a javascript file, we would put the javascript_include_tag inside a content_for block, like so:<br />
<code>&lt;% content_for :head_includes do %&gt;<br />
&lt;%= javascript_include_tag "search.js" %&gt;<br />
&lt;% end %&gt;</code><br />
This worked quite well for us in rails 3.0.  However, in Rails 3.1 with the asset pipeline enabled, this would throw an error:<br />
<code>search.js isn't precompiled</code><br />
My first attempt at getting this to work was to run<br />
<code>bundle exec rake assets:precompile</code></p>
<p>This compiled all of my coffeescript assets, as well as application.js, however the default rails configuration doesn&#8217;t precompile files with .js or .css extensions (although .js.coffee or .css.scss would be precompiled).  I could have renamed all of my files to end with .js.coffee, but I wanted to move away from declaring individual files on various views, and I wanted javascript files that are run on similar pages to be bundled together.  The rails guide had this bit of advice:</p>
<p>You should put any JavaScript or CSS unique to a controller inside their respective asset files, as these files can then be loaded just for these controllers with lines such as <tt>&lt;%= javascript_include_tag params[:controller] %&gt;</tt> or <tt>&lt;%= stylesheet_link_tag params[:controller] %&gt;</tt>.</p>
<p>This was decent advice, however the assets still weren&#8217;t being compiled.  That would take a few more steps.  First, I created a manifest file for any controller that had controller specific javascripts.  For example, if a controller named EventsController had specific javascript files, I would create events.js (if it didn&#8217;t already exist).  To that file, I added the following statements:</p>
<p><code>//= require_tree "./events"</code></p>
<p>I would also include the following if the file already existed with existing javascript:</p>
<p><code>//= require_self</code></p>
<p>I would then dump any controller specific .js files into the folder specified by the require_tree directive.  I also had to add the manifest files to the list of files to precompile by adding the following to config/application.rb (with an entry for each manifest file, comma separated):</p>
<p><code>config.assets.precompile += ['events.js', 'pages.js']</code></p>
<p>For the sake of organization, I also moved a lot of javascript files to vendor/assets/javascripts and lib/assets/javascripts, as appropriate.  I then updated application.rb to list all of the files that needed to be included on every page, using require and require_tree directives.  I then was able to replace my various javascript_include_tag lines in my application.html.erb file with the following:</p>
<p><code>&lt;%= stylesheet_link_tag 'application'%&gt;<br />
&lt;%= stylesheet_link_tag controller.controller_name if individual_css_file_exists?(controller.controller_name) %&gt;<br />
&lt;%= javascript_include_tag 'application' %&gt;<br />
&lt;%= javascript_include_tag controller.controller_name if individual_js_file_exists?(controller.controller_name) %&gt;</code></p>
<p>Note that controller.controller_name is similar to params[:controller], except where you have namespaced controllers. For example, Admin::EventsController would return &#8220;events&#8221; for controller.controller_name, and &#8220;admin/events&#8221; if you use params[:controller].  I chose the former for simplicity&#8217;s sake.  I also created the following helpers in application_helper.rb</p>
<p><code>def individual_css_file_exists?(name)<br />
  !GoVoluntr::Application.assets.find_asset("#{name}.css").nil?<br />
end</p>
<p> def individual_js_file_exists?(name)<br />
  !GoVoluntr::Application.assets.find_asset("#{name}.js").nil?<br />
end</code></p>
<p>This helped to avoid the dreaded &#8220;controller.js is not precompiled&#8221; error when a manifest file didn&#8217;t exist for that specific controller.</p>
<p>This may seem like an awful lot of work for the application to essentially work the same as it did before.  The benefit, however, is that I can remove a lot of redundant code from each of my view files, and I get a reasonable tradeoff between combining multiple javascript files and only loading certain code on specific pages.</p>
]]></content:encoded>
			<wfw:commentRss>http://justinspowers.com/2011/12/rails-3-1-asset-pipeline-automation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Of Capistrano, Github, and Branches (or, a forking mess)</title>
		<link>http://justinspowers.com/2009/10/of-capistrano-github-and-branches-or-a-forking-mess/</link>
		<comments>http://justinspowers.com/2009/10/of-capistrano-github-and-branches-or-a-forking-mess/#comments</comments>
		<pubDate>Tue, 27 Oct 2009 01:58:25 +0000</pubDate>
		<dc:creator>Justin</dc:creator>
				<category><![CDATA[Capistrano]]></category>
		<category><![CDATA[Efficiency]]></category>
		<category><![CDATA[Github]]></category>
		<category><![CDATA[Photify.net]]></category>
		<category><![CDATA[Rails]]></category>

		<guid isPermaLink="false">http://justinspowers.com/?p=23</guid>
		<description><![CDATA[Disclaimer: I am a Github newbie, and I am still learning the various concepts. If I misrepresent something in this post, please let me know in the comments! I recently switched my project over from SVN to Github. My reasons were varied, but a large reason was because I needed to create various branches to [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Disclaimer:</strong> I am a Github newbie, and I am still learning the various concepts.  If I misrepresent something in this post, please let me know in the comments!</p>
<p>I recently switched my project over from SVN to Github.  My reasons were varied, but a large reason was because I needed to create various branches to accomodate my ADD style of development (work on layouts for a bit, then switch to security, then switch to fine tuning my models).  I also need to create a branch for productions servers, as well as a branch for my staging server, which is set up at home.  The latter was a bit confusing at first, until I found a great tutorial <a href="http://weblog.jamisbuck.org/2007/7/23/capistrano-multistage" onclick="pageTracker._trackPageview('/outgoing/weblog.jamisbuck.org/2007/7/23/capistrano-multistage?referer=');">here</a>.</p>
<p>First, a couple of notes about my setup.  I am the sole contributor to my (private) repository.  Up until now, I have not had a need for this &#8220;forking&#8221; business that I see from time to time.  In configuring up my multistage setup, I ran into an issue when I tried to use <code>set :branch, "2.0"</code> in my staging deploy.rb file.  Even though I had created a branch for &#8220;2.0&#8243; like so:<br />
<code>git branch 2.0</code><br />
I was getting the following error:<br />
<code>`query_revision': Unable to resolve revision for 'invalid' on repository 'git@github.com:*****/******.git'. (RuntimeError)</code><br />
This confused me for quite some time, until I found out that the set :branch isn&#8217;t referring to the branches that I had created locally, but to github forks.  To create a fork from the branch, I simply had to do the following:<br />
<code>git checkout 2.0<br />
git push origin 2.0</code></p>
<p>The origin bit is what does the magic.  As soon as I refreshed, I was able to see the newly created fork in the github web UI, and my deploy recipe worked like magic.  Brilliant!</p>
<p>Note: I still have to find out how this will affect my git workflow, but since the clone URL is still the same, it seems that I should still be able to continue with my current way of doing things.</p>
]]></content:encoded>
			<wfw:commentRss>http://justinspowers.com/2009/10/of-capistrano-github-and-branches-or-a-forking-mess/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

