<?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>Blog &#124; The Working Group &#187; ruby</title>
	<atom:link href="http://blog.twg.ca/tag/ruby/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.twg.ca</link>
	<description></description>
	<lastBuildDate>Thu, 05 Aug 2010 15:21:25 +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>Active state for link_to == active_link_to. A solution for building navigation systems in Rails.</title>
		<link>http://blog.twg.ca/2009/11/active-state-for-link_to-active_link_to/</link>
		<comments>http://blog.twg.ca/2009/11/active-state-for-link_to-active_link_to/#comments</comments>
		<pubDate>Fri, 27 Nov 2009 18:07:45 +0000</pubDate>
		<dc:creator>Oleg</dc:creator>
				<category><![CDATA[Tech]]></category>
		<category><![CDATA[active state]]></category>
		<category><![CDATA[active_link]]></category>
		<category><![CDATA[active_link_to]]></category>
		<category><![CDATA[github]]></category>
		<category><![CDATA[navigation]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[ruby on rails]]></category>

		<guid isPermaLink="false">http://blog.twg.ca/?p=346</guid>
		<description><![CDATA[I have a question for you. How do you deal with the logic of setting links as active in your navs? Actually, I don&#8217;t want to know. It&#8217;s probably awful. I might have a pretty good solution for you. Let&#8217;s take a look at a very simple nav. These examples all use HAML: %ul &#160; [...]]]></description>
			<content:encoded><![CDATA[<p>I have a question for you. How do you deal with the logic of setting links as active in your navs?</p>
<p>Actually, I don&#8217;t want to know. It&#8217;s probably awful. I might have a pretty good solution for you. Let&#8217;s take a look at a very simple nav. These examples all use <a href="http://haml-lang.com/">HAML</a>:</p>
<div class="codecolorer-container ruby default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color:#006600; font-weight:bold;">%</span>ul<br />
&nbsp; <span style="color:#006600; font-weight:bold;">%</span>li= link_to <span style="color:#996600;">'Home'</span>, home_path<br />
&nbsp; <span style="color:#006600; font-weight:bold;">%</span>li= link_to <span style="color:#996600;">'Puppies'</span>, puppies_path<br />
&nbsp; <span style="color:#006600; font-weight:bold;">%</span>li= link_to <span style="color:#996600;">'Kittens'</span>, kittens_path<br />
&nbsp; <span style="color:#006600; font-weight:bold;">%</span>li= link_to <span style="color:#996600;">'Froggies'</span>, froggies_path</div></div>
<p>Right, that&#8217;s great. But how do I insert logic as to what link gets marked as active? To begin, let&#8217;s quickly install this random gem:</p>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #c20cb9; font-weight: bold;">sudo</span> gem <span style="color: #c20cb9; font-weight: bold;">install</span> active_link_to</div></div>
<p>And then change our nav a bit:</p>
<div class="codecolorer-container ruby default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color:#006600; font-weight:bold;">%</span>ul<br />
&nbsp; <span style="color:#006600; font-weight:bold;">%</span>li= active_link_to <span style="color:#996600;">'Home'</span>, home_path<br />
&nbsp; <span style="color:#006600; font-weight:bold;">%</span>li= active_link_to <span style="color:#996600;">'Puppies'</span>, puppies_path<br />
&nbsp; <span style="color:#006600; font-weight:bold;">%</span>li= active_link_to <span style="color:#996600;">'Kittens'</span>, kittens_path<br />
&nbsp; <span style="color:#006600; font-weight:bold;">%</span>li= active_link_to <span style="color:#996600;">'Froggies'</span>, froggies_path</div></div>
<p>And that&#8217;s pretty much it.</p>
<p>So, for example, if you navigate to /kittens/1-my-fluffy-kitten navigation link for &#8216;Kittens&#8217; will have &#8216;active&#8217; class attached to it. It&#8217;s almost like magic.</p>
<p>You probably noticed that &#8216;Home&#8217; is highlighted as well. It happened because whatever URL you are currently on is a child of the home_path. I guess we want to mark it as active only if we find ourselves on the home page and not anywhere else. We can fix this:</p>
<div class="codecolorer-container ruby default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color:#006600; font-weight:bold;">%</span>ul<br />
&nbsp; <span style="color:#006600; font-weight:bold;">%</span>li= active_link_to <span style="color:#996600;">'Home'</span>, home_path, <span style="color:#ff3333; font-weight:bold;">:active</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#123;</span>:<span style="color:#9966CC; font-weight:bold;">when</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:self_only</span><span style="color:#006600; font-weight:bold;">&#125;</span><br />
&nbsp; <span style="color:#006600; font-weight:bold;">%</span>li= active_link_to <span style="color:#996600;">'Puppies'</span>, puppies_path<br />
&nbsp; <span style="color:#006600; font-weight:bold;">%</span>li= active_link_to <span style="color:#996600;">'Kittens'</span>, kittens_path<br />
&nbsp; <span style="color:#006600; font-weight:bold;">%</span>li= active_link_to <span style="color:#996600;">'Froggies'</span>, froggies_path</div></div>
<p>Hey, wanna render a sub nav when you find yourself browsing /puppies or any page under that URL? It&#8217;s just sooo easy:</p>
<div class="codecolorer-container ruby default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color:#006600; font-weight:bold;">%</span>ul<br />
&nbsp; <span style="color:#006600; font-weight:bold;">%</span>li= active_link_to <span style="color:#996600;">'Home'</span>, home_path, <span style="color:#ff3333; font-weight:bold;">:active</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#123;</span>:<span style="color:#9966CC; font-weight:bold;">when</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:self_only</span><span style="color:#006600; font-weight:bold;">&#125;</span><br />
&nbsp; <span style="color:#006600; font-weight:bold;">%</span>li<br />
&nbsp; &nbsp; = active_link_to <span style="color:#996600;">'Puppies'</span>, puppies_path<br />
&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">-</span> <span style="color:#9966CC; font-weight:bold;">if</span> is_active_link?<span style="color:#006600; font-weight:bold;">&#40;</span>puppies_path<span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">%</span>ul<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">%</span>li= active_link_to <span style="color:#996600;">'Big'</span>, big_puppies_path<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">%</span>li= active_link_to <span style="color:#996600;">'Small'</span>, small_puppies_path<br />
&nbsp; <span style="color:#006600; font-weight:bold;">%</span>li= active_link_to <span style="color:#996600;">'Kittens'</span>, kittens_path<br />
&nbsp; <span style="color:#006600; font-weight:bold;">%</span>li= active_link_to <span style="color:#996600;">'Froggies'</span>, froggies_path</div></div>
<p>And that&#8217;s the skinny of what active_link_to is for.</p>
<p>For more documentation on more functionality checkout project on GitHub: <a href="http://github.com/theworkinggroup/active_link_to">http://github.com/theworkinggroup/active_link_to</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.twg.ca/2009/11/active-state-for-link_to-active_link_to/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Livin&#8217; on the edge: Ruby, Rails, and Snow Leopard</title>
		<link>http://blog.twg.ca/2009/09/livin-on-the-edge-ruby-rails-and-snow-leopard/</link>
		<comments>http://blog.twg.ca/2009/09/livin-on-the-edge-ruby-rails-and-snow-leopard/#comments</comments>
		<pubDate>Wed, 02 Sep 2009 18:38:35 +0000</pubDate>
		<dc:creator>Georges</dc:creator>
				<category><![CDATA[Tech]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[snow leopard]]></category>

		<guid isPermaLink="false">http://blog.twg.ca/?p=102</guid>
		<description><![CDATA[Snow Leopard is out and I like having the latest and greatest, so I bought a new hard drive and clean installed Snow Leopard on it. This meant that I had the opportunity to reinstall my development environment with the benefit of a few years of experience and the advice of my fellow TWG&#8217;ers. Here&#8217;s [...]]]></description>
			<content:encoded><![CDATA[<p>Snow Leopard is out and I like having the latest and greatest, so I bought a new hard drive and clean installed Snow Leopard on it. This meant that I had the opportunity to reinstall my development environment with the benefit of a few years of experience and the advice of my fellow TWG&#8217;ers.</p>
<p>Here&#8217;s how I got my newly installed Snow Leopard up to speed for Rails development.</p>
<p><img src="http://theworkinggroup.ca/system/files/16/original/snow-leopard-rails.jpg" alt="Ruby on Rails on Snow Leopard" width="500" height="230" /></p>
<h2>Ruby 1.9.1</h2>
<p>First, I got Ruby up to date. Snow Leopard  comes with Ruby 1.8.7 by default. There are many benefits to going with Ruby 1.9.1, so I went with that.</p>
<p>I wasn&#8217;t 100% ready to commit to Ruby 1.9.1, so I used <a title="rvm - ruby version manager" href="http://rvm.beginrescueend.com">rvm</a> to manage my Ruby interpreters. Many gems aren&#8217;t ready for 1.9 prime-time, so I wanted the ability to drop back to Ruby 1.8 if this blew up in my face. For an overview of what is working under Ruby 1.9, check out <a title="Is it Ruby 1.9?" href="http://www.isitruby19.com">isitruby19.com</a>.</p>
<p>I installed rvm with:</p>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #c20cb9; font-weight: bold;">sudo</span> gem <span style="color: #c20cb9; font-weight: bold;">install</span> rvm<br />
rvm-install</div></div>
<p>Check out <a title="rvm - ruby version manager" href="http://rvm.beginrescueend.com">the rvm site</a> for more information. There&#8217;s some great documentation there.</p>
<p>Next, I ran</p>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">rvm list</div></div>
<p>to see all my installed Ruby interpreters. When you do this, you&#8217;ll see that the only Ruby installed is the system Ruby 1.8.7.</p>
<p>I ran <code class="codecolorer bash default"><span class="bash">ruby <span style="color: #660033;">-v</span></span></code> to see which Ruby was being used by default. I saw that I was using Ruby 1.8.7:</p>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">ruby 1.8.7 <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">2008</span>-08-<span style="color: #000000;">11</span> patchlevel <span style="color: #000000;">72</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span>universal-darwin10.0<span style="color: #7a0874; font-weight: bold;">&#93;</span></div></div>
<p><code class="codecolorer bash default"><span class="bash">rvm</span></code> will happily install and activate any version of Ruby you want.<br />
I got it to install Ruby 1.9.1 with the following:</p>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">rvm use ruby <span style="color: #660033;">-v</span> 1.9.1</div></div>
<p>rvm will check to see if 1.9.1 is installed and, if it isn&#8217;t, it will download and install it for you. Once that is done, I ran <code class="codecolorer bash default"><span class="bash">rvm list</span></code> again and now saw Ruby 1.9.1 listed as well as Snow Leopard system Ruby.</p>
<p>After that was complete, I ran <code class="codecolorer bash default"><span class="bash">rvm 1.9.1</span></code>, and then <code class="codecolorer bash default"><span class="bash">ruby <span style="color: #660033;">-v</span></span></code> and saw that it worked:</p>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">ruby 1.9.1p243 <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">2009</span>-07-<span style="color: #000000;">16</span> revision <span style="color: #000000;">24175</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span>i386-darwin10.0.0<span style="color: #7a0874; font-weight: bold;">&#93;</span></div></div>
<p>But, I wanted Ruby 1.9.1 to be the default on my system. I got rvm to set that default by executing:</p>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">rvm 1.9.1 <span style="color: #660033;">--default</span></div></div>
<p>Now, the system is set to use Ruby 1.9.1 by default.</p>
<p><em>Side note</em>: one of the neat features of rvm is that it can change your Ruby interpreter on-the-fly for you. This change isn&#8217;t permanent and only lasts for as long your Terminal session is open. For example, you can open one Terminal, execute &#8216;rvm system&#8217;, and have that Terminal use the Snow Leopard Ruby 1.8.7 while another one is running Ruby 1.9.1. This is <em>very</em> handy for compatibility testing.</p>
<h2>MySQL</h2>
<p>The next piece of the puzzle was MySQL. I have found that the best way to install packages like MySQL is via MacPorts.</p>
<p>If you haven&#8217;t done it yet, <a title="MacPorts" href="http://www.macports.org/install.php ">install MacPorts from here</a>. There&#8217;s a package for Snow Leopard, so be sure to select that one.</p>
<p>The MacPorts MySQL package is called <code class="codecolorer bash default"><span class="bash">mysql5-server-devel</span></code>, so I installed that:</p>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #c20cb9; font-weight: bold;">sudo</span> port <span style="color: #c20cb9; font-weight: bold;">install</span> mysql5-server-devel</div></div>
<p>MacPorts will handle all the dependencies and then install MySQL. I followed all the post-install steps that the installer recommended &#8211; start-up items, etc. The MySQL it installed is 64-bit, as it should be.</p>
<p>I then had to connect Ruby with MySQL and I needed the gem for that. To properly install the gem, I had to specify the architecture and the location of the mysql_config5 utility. The arch setting ensured that I got a 64-bit gem to go along with my new 64-bit MySQL installation.</p>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><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> <span style="color: #c20cb9; font-weight: bold;">sudo</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>opt<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>mysql_config5</div></div>
<h2>Ruby Gems</h2>
<p>I then ran <code class="codecolorer bash default"><span class="bash">gem list</span></code> to see what gems I had installed. If you do this, you&#8217;ll see what I saw: not much. This makes a lot of sense because gems are installed relative to the version of Ruby they were installed with. So, all the gems that Snow Leopard had installed for Ruby 1.8.7 are no longer around for use. It was at this point that I was happy I used <code class="codecolorer bash default"><span class="bash">rvm</span></code>. I dropped back to 1.8.7, got the list of installed gems and proceeded to re-install them under Ruby 1.9. But, <em>dear reader</em>, you don&#8217;t need to do this! Here&#8217;s how to get back to the default Snow Leopard gems under Ruby 1.9:</p>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #c20cb9; font-weight: bold;">sudo</span> gem <span style="color: #c20cb9; font-weight: bold;">install</span> actionmailer actionpack actionwebservice activerecord activeresource activesupport acts_as_ferret builder capistrano cgi_multipart_eof_fix chronic daemons dnssd fastthread gem_plugin haml highline hoe hpricot javan-whenever libxml-ruby mdalessio-dryopteris needle net-scp net-sftp net-ssh net-ssh-gateway nokogiri pauldix-feedzirra pauldix-sax-machine rack rails rake RedCloth ruby-openid ruby-yadis rubyforge rubygems-update rubynode rvm taf-curb</div></div>
<p>This&#8217;ll take a while. Go grab a coffee. Run around the block. Do something fun.</p>
<p>If any of these fail for you, check out <a title="Is it Ruby 1.9?" href="http://www.isitruby19.com">isitruby19.com</a> for tips on how to get it working.</p>
<h2>Passenger</h2>
<p>The next piece I needed was <a title="Passenger aka mod_rails" href="http://www.modrails.com">Passenger aka mod_rails</a>. I needed version 2.2.5 (newest as of writing) for this to all work together. I installed it with:</p>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #c20cb9; font-weight: bold;">sudo</span> gem <span style="color: #c20cb9; font-weight: bold;">install</span> passenger</div></div>
<p>This retrieved and compiled Passenger 2.2.5 for me. It might get a newer version for you. Once that completed, I ran:</p>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #c20cb9; font-weight: bold;">sudo</span> passenger-install-apache2-module</div></div>
<p>The Passenger module depends on your current Ruby version, so you have to re-compile Passenger if you change your Ruby version. It is important that the Passenger compilation properly links with the Ruby interpreter you want to use. In this case, that&#8217;s Ruby 1.9.1.</p>
<p>When you do this the Passenger installation, double-check the  paths that the Passenger compilation process outputs and ensure that it is properly finding the Ruby 1.9.1 installed in your .rvm directory. If you see paths that <em><strong>don&#8217;t</strong></em> go to .rvm in your home directory, then it is <em><strong>doing it wrong</strong></em>. If this happens, ensure that rvm is set to use 1.9.1 by default and try again.</p>
<p>Next, I edited my httpd.conf just as the Passenger installer recommended. I opened it up with <code class="codecolorer bash default"><span class="bash">open <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>apache2<span style="color: #000000; font-weight: bold;">/</span>httpd.conf</span></code> and pasted in the Passenger lines.</p>
<p>The Passenger Preference Pane makes everything easier, so definitely wanted that.<br />
I got lucky and found that <a title="Passenger Preference Pane" href="http://www.fngtps.com/2009/09/new-os-more-pane-passenger-preference-pane-v1-3">it had <em>just been updated</em> to support Snow Leopard</a>, so make sure you get version 1.3 or greater.</p>
<h2>Taa daa!</h2>
<p>That&#8217;s it!<br />
Set up a Rails project in the Passenger Preference Pane and try it out! You should see your fully functional Rails app running.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.twg.ca/2009/09/livin-on-the-edge-ruby-rails-and-snow-leopard/feed/</wfw:commentRss>
		<slash:comments>20</slash:comments>
		</item>
	</channel>
</rss>
