<?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 on the Run &#187; gem</title>
	<atom:link href="http://railsontherun.com/tag/gem/feed/" rel="self" type="application/rss+xml" />
	<link>http://railsontherun.com</link>
	<description>Rails experiments by Matt Aimonetti</description>
	<lastBuildDate>Tue, 23 Feb 2010 07:28:00 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
		<item>
		<title>Googlecharts 1.5.1</title>
		<link>http://railsontherun.com/2010/02/03/googlecharts-1-5-1/</link>
		<comments>http://railsontherun.com/2010/02/03/googlecharts-1-5-1/#comments</comments>
		<pubDate>Thu, 04 Feb 2010 05:18:23 +0000</pubDate>
		<dc:creator>Matt Aimonetti</dc:creator>
				<category><![CDATA[Gems & Libs]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[googlecharts]]></category>
		<category><![CDATA[charts]]></category>
		<category><![CDATA[gem]]></category>
		<category><![CDATA[google charts]]></category>

		<guid isPermaLink="false">http://railsontherun.com/?p=1722</guid>
		<description><![CDATA[To celebrate the relaunch of this site and since we are waiting for Rails 3.0 beta to be released, I figured I should share with you what I worked on the other night.
I merged patches, refactored and released a new version of googlecharts, my Gem to create graphs using Google Chart API.
sudo gem install googlecharts
Here [...]]]></description>
			<content:encoded><![CDATA[<p>To celebrate the relaunch of this site and since we are waiting for Rails 3.0 beta to be released, I figured I should share with you what I worked on the other night.</p>
<p>I merged patches, refactored and released a new version of googlecharts, my Gem to create graphs using Google Chart API.</p>
<p><code>sudo gem install googlecharts</code></p>
<p>Here is a quick example of how the API works when dealing with a complex graph:</p>
<pre class="brush:ruby">require 'gchart' # or require 'googlecharts' if you prefer to use the Googlecharts constant.
title = "Player Count"
size = "575x300"
data = [85,107,123,131,155,172,173,189,203,222,217,233,250,239,256,267,247,261,275,295,288,305,322,307,325,347,331,346,363,382,343,359,383,352,374,393,358,379,396,416,377,398,419,380,409,426,453,432,452,465,436,460,480,440,457,474,501,457,489,507,347,373,413,402,424,448,475,488,513,475,507,530,440,476,500,518,481,512,531,367,396,423,387,415,446,478,442,469,492,463,489,508,463,491,518,549,503,526,547,493,530,549,493,520,541,564,510,535,564,492,512,537,502,530,548,491,514,538,568,524,548,568,512,533,552,577,520,545,570,516,536,555,514,536,566,521,553,579,604,541,569,595,551,581,602,549,576,606,631,589,615,650,597,624,646,672,605,626,654,584,608,631,574,597,622,559,591,614,644,580,603,629,584,615,631,558,591,618,641,314,356,395,397,429,450,421,454,477,507,458,490,560,593]
Gchart.line(:title =&gt; title, :size =&gt; size, :data =&gt; data, :axis_with_labels =&gt; 'x,y', :line_color =&gt; '1e60cc', :axis_labels =&gt; [(1.upto(24).to_a &lt;&lt; 1)], :max_value =&gt; 700, :custom =&gt; 'chg=10,15,1,0')
</pre>
<p>Which provides you with the url or image tag (or downloaded file) that produces the following graph:</p>
<p><img title="Player Count" src="http://chart.apis.google.com/chart?chxl=0:|1|2|3|4|5|6|7|8|9|10|11|12|13|14|15|16|17|18|19|20|21|22|23|24|1&amp;chxt=x,y&amp;chco=1e60cc&amp;chg=10,15,1,0&amp;chd=s:HJKLNPPQRTTUWVWXVXYaZbcbcedeghefhfhifhjkhjlhklomopmoqmopsorsehkjlnqrtqsumqstqtvgjliknqnprprsprtwsuwruwruvxtvxrtvsuwrtvyuwytvwzuwytvxtvyuwz1vy0wz1wz130250357135z13y03x025z13z23x024bfijlnloqsorx0&amp;chtt=Player+Count&amp;cht=lc&amp;chs=575x300&amp;chxr=1,85,700" alt="Google Chart" width="575" height="300" /></p>
<p>This release works great with Ruby 1.9 and <a title="MacRuby" href="http://macruby.org" target="_blank">MacRuby</a>, lots of bugs got fixed and some new features were added. Something a lot of people complained was that the gem was called googlecharts but that the main class was called Gchart. The problem was that I wrote my gem and called it Gchart and when I went to register the rubyforge project page, the name was already taken. In this release, I fixed this problem by allowing users to require and use the constant name they want, Gchart or Googlecharts. I also spent quite a lot of time cleaning up the old code which I was a bit ashamed of. Class variables are now removed and overall, the code should be a bit more sane.</p>
<p>The source code can be found in my <a href="http://github.com/mattetti/googlecharts/" target="_blank">GitHub accout</a> and the documentation <a href="http://mattetti.github.com/googlecharts/" target="_blank">there</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://railsontherun.com/2010/02/03/googlecharts-1-5-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Googlecharts featured on Github</title>
		<link>http://railsontherun.com/2008/06/27/googlecharts-featured-on-github/</link>
		<comments>http://railsontherun.com/2008/06/27/googlecharts-featured-on-github/#comments</comments>
		<pubDate>Fri, 27 Jun 2008 07:06:00 +0000</pubDate>
		<dc:creator>Matt Aimonetti</dc:creator>
				<category><![CDATA[Gems & Libs]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[googlecharts]]></category>
		<category><![CDATA[community]]></category>
		<category><![CDATA[fork]]></category>
		<category><![CDATA[gem]]></category>
		<category><![CDATA[github]]></category>

		<guid isPermaLink="false">http://railsontherun.com/2008/06/27/googlecharts-featured-on-github</guid>
		<description><![CDATA[Github, probably the most famous social code hosting service just redesigned their homepage and are now featuring hosted projects.
I got a very good surprise when Takeo from Powerset &#38; Stafftool hall of fame mentioned to me that Github picked one of my gems as the first featured project!

By the way, Takeo is also a Googlecharts [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://github.com">Github</a>, probably the most famous social code hosting service just <a href="http://github.com/blog/103-new-homepage">redesigned their homepage</a> and are now featuring hosted projects.</p>
<p>I got a very good surprise when <a href="http://github.com/takeo">Takeo</a> from <a href="http://powerset.com">Powerset</a> &amp; <a href="http://stafftool.com">Stafftool</a> hall of fame mentioned to me that <a href="http://github.com">Github</a> picked one of my gems as the first featured project!</p>
<p><img src="http://img.skitch.com/20080627-r14subqdx2ye3w13qefbx974gc.png" alt="github"/></p>
<p>By the way, Takeo is also a Googlecharts contributor (+ a Merbist) and I had the honor to be the first one he ever forked!</p>
<p>Another Googlecharts user, <a href="http://graffletopia.com">Mokolabs</a> from Graffletopia and <a href="http://icalshare.com/">iCal Share</a> also decided to try Git and Github. In no time he had forked my project, made some modifications and sent me a pull request. w00t w00t!</p>
<p>To celebrate, we released version 1.3.4 with cleaner documentation, and enhanced features.</p>
<p><a href="http://googlecharts.rubyforge.org/">Documentation</a> &amp; <a href="http://github.com/mattetti/googlecharts">Code Repo</a></p>
<p>Thanks to everyone involved in this project. And special kudos to the <a href="http://github.com">GitHub</a> team for offering such an awesome service!</p>
]]></content:encoded>
			<wfw:commentRss>http://railsontherun.com/2008/06/27/googlecharts-featured-on-github/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Googlecharts 0.1.0 released with new site</title>
		<link>http://railsontherun.com/2007/12/12/googlecharts-0-1-0-released-with-new-site/</link>
		<comments>http://railsontherun.com/2007/12/12/googlecharts-0-1-0-released-with-new-site/#comments</comments>
		<pubDate>Wed, 12 Dec 2007 08:02:00 +0000</pubDate>
		<dc:creator>Matt Aimonetti</dc:creator>
				<category><![CDATA[Gems & Libs]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[googlecharts]]></category>
		<category><![CDATA[chart]]></category>
		<category><![CDATA[charts]]></category>
		<category><![CDATA[gem]]></category>
		<category><![CDATA[googlechart]]></category>

		<guid isPermaLink="false">http://railsontherun.com/2007/12/12/googlecharts-0-1-0-released-with-new-site</guid>
		<description><![CDATA[I just released Googlecharts 0.1.0 (few bug fixes and enhancements).

The first thing you want to do is to install the gem


sudo gem install googlecharts


The second thing you want to do is check the great brand new website for googlecharts




The third thing you want to do is to recommend me on Working with Rails  


The [...]]]></description>
			<content:encoded><![CDATA[<p>I just released Googlecharts 0.1.0 (few bug fixes and enhancements).</p>
<ul>
<li>The first thing you want to do is to install the gem</li>
</ul>
<pre class='brush:bash'>
sudo gem install googlecharts
</pre>
<ul>
<li>The second thing you want to do is check <a href="http://googlecharts.rubyforge.org/">the great brand new website</a> for <a href="http://googlecharts.rubyforge.org/">googlecharts</a></li>
</ul>
<p><img src="http://content.screencast.com/media/40c8b83c-06e5-4d07-89d5-8f05ae37e3a9_74569570-772f-4886-b2ea-f305d1ede3aa_static_0_0_00000037.png" alt="website"/></p>
<ul>
<li>
<p>The third thing you want to do is to <a href="http://www.workingwithrails.com/recommendation/new/person/6065-matt-aimonetti">recommend me on Working with Rails</a> <img src='http://railsontherun.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
</li>
<li>
<p>The fourth thing you want to do is to submit patches, suggestions etc&#8230;</p>
</li>
<li>
<p>The fifth thing you want to do is to develop an awesome website using sexy googlecharts</p>
</li>
</ul>
<p>This gem and its website have been made possible by <a href="http://drnicwilliams.com/">DrNic</a> and his awesome <a href="http://newgem.rubyforge.org/">new gem generator</a> and has been developed following the BDD approach thanks to <a href="http://rspec.rubyforge.org">RSpec</a> <img src='http://railsontherun.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://railsontherun.com/2007/12/12/googlecharts-0-1-0-released-with-new-site/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Google Chart Gem</title>
		<link>http://railsontherun.com/2007/12/10/google-chart-gem/</link>
		<comments>http://railsontherun.com/2007/12/10/google-chart-gem/#comments</comments>
		<pubDate>Mon, 10 Dec 2007 06:43:00 +0000</pubDate>
		<dc:creator>Matt Aimonetti</dc:creator>
				<category><![CDATA[Gems & Libs]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[googlecharts]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[chart]]></category>
		<category><![CDATA[charts]]></category>
		<category><![CDATA[gchart]]></category>
		<category><![CDATA[gem]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[sexy charts]]></category>

		<guid isPermaLink="false">http://railsontherun.com/2007/12/12/google-chart-gem</guid>
		<description><![CDATA[update Nov 11: the gem is finally available there or simply:

  sudo gem install googlecharts

Note that I&#8217;m working on merging this gem with another Google Charts gem. (see comments for more info about that)

I&#8217;ve been working on a Google Chart Gem that I have ready for a beta release but unfortunately, getting a new [...]]]></description>
			<content:encoded><![CDATA[<h2>update Nov 11: the gem is finally available <a href="http://rubyforge.org/projects/googlecharts/">there</a> or simply:</h2>
<pre class="brush:bash">
  sudo gem install googlecharts
</pre>
<p>Note that I&#8217;m working on merging this gem with another Google Charts gem. (see comments for more info about that)</p>
<p><img src="http://chart.apis.google.com/chart?chtt=Rails+on+the+run&amp;cht=p3&amp;chs=200x90&amp;chd=s:Hellobla&amp;chl=May|Jun|Jul|Aug|Sep|Oct&amp;chco=0000ff" alt="gchart"/></p>
<p>I&#8217;ve been working on a Google Chart Gem that I have ready for a beta release but unfortunately, getting a new project setup on RubyForge takes forever. (apparently 72 hours)</p>
<p>It&#8217;s mainly a wrapper for the great GChart API, but instead of using a helper to generate your graphs, you can simply do:</p>
<pre class="brush:ruby">
  Gchart.bar(:title => 'My Mojo', :data => [1,2,4,67,100,41,234], :max_value => 300, :bg => 'c3c3c3')

  Gchart.line(:title => 'My Mojo',
              :data => [[1,2,4,67,100,41,234],[41,63,96,17,100,14,423]],
              :bg => '666666',
              :graph_bg => 'cccccc',
              :line_colors => 'ff0000,00ff00',
              :legend => ['morning','evening'])
</pre>
<pre class="brush:ruby">
  Gchart.pie(:data => [20,10,15,5,50], :title => 'SDRuby fu', :size => '400x200', :labels => ['matt', 'rob', 'patrick', 'jordan', 'ryan'])
</pre>
<p><img src="http://chart.apis.google.com/chart?chs=400x200&amp;chd=s:YMSG9&amp;chtt=SDRuby+fu&amp;chl=matt|rob|patrick|jordan|ryan&amp;cht=p" alt="img"/></p>
<p>As far as I know this is most complete Ruby wrapper for Google Chart API, but feel free to look around.</p>
]]></content:encoded>
			<wfw:commentRss>http://railsontherun.com/2007/12/10/google-chart-gem/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>a new useless Gem</title>
		<link>http://railsontherun.com/2007/12/04/a-new-useless-gem/</link>
		<comments>http://railsontherun.com/2007/12/04/a-new-useless-gem/#comments</comments>
		<pubDate>Tue, 04 Dec 2007 08:28:00 +0000</pubDate>
		<dc:creator>Matt Aimonetti</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[activation code]]></category>
		<category><![CDATA[DrNic]]></category>
		<category><![CDATA[gem]]></category>
		<category><![CDATA[generator]]></category>
		<category><![CDATA[lorem ipsum]]></category>
		<category><![CDATA[newgem]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[sqlite3]]></category>

		<guid isPermaLink="false">http://railsontherun.com/2007/12/04/a-new-useless-gem</guid>
		<description><![CDATA[During Thanksgiving break I had fun with a friend of mine working on a Ruby challenge while digesting the traditional turkey.
]]></description>
			<content:encoded><![CDATA[<p>During Thanksgiving break I had fun with a friend of mine working on a Ruby challenge while digesting the traditional turkey.</p>
<p><img src="http://content.screencast.com/media/a088950c-c9d1-4655-9b6e-b917e04dd6ec_74569570-772f-4886-b2ea-f305d1ede3aa_static_0_0_00000026.png" alt="http://content.screencast.com/media/a088950c-c9d1-4655-9b6e-b917e04dd6ec<em>74569570-772f-4886-b2ea-f305d1ede3aa</em>static<em>0</em>0_00000026.png&#8221;/></p>
<p>The challenge was quite simple, create a small library that can generate random words from the English dictionary. </p>
<p>But of course there was a twist. One should be able to choose the total amount of characters, the amount of words and the separator between the words. However we both had a <a href="http://wordlist.sourceforge.net/">word list</a>.</p>
<p>I personally decided to use <a href="http://www.sqlite.org/">SQlite3</a> to store the words after parsing the text file if the database is empty.</p>
<p>It was a good exercise and it got me to play with SQLite and one of the <a href="http://rubyforge.org/projects/sqlite-ruby/">Ruby adapter library</a>. Once I was done, I decide to play with <a href="http://drnicwilliams.com/">DrNic</a> cool <a href="http://newgem.rubyforge.org/">Gem generator</a>.</p>
<p><img src="http://static.flickr.com/50/130749539_89959dd059_t.jpg" alt="http://static.flickr.com/50/130749539<em>89959dd059</em>t.jpg&#8221;/> </p>
<p>Nic is my favorite Aussie&#8217;s Rubyist (ok, I don&#8217;t know many) and I&#8217;ve been wanting to check on this lib for a very long time. And I have to say he did an awesome job! Writing a Ruby Gem has never that easy! And on top of that the generator creates RSpec examples (or test/unit tests), a basic website for your gem and has a bunch of rake tasks to deploy your newly created gem.</p>
<p>Feel free to check the source code:</p>
<p><a href="http://random-word-gen.rubyforge.org/svn/">http://random-word-gen.rubyforge.org/svn/</a></p>
<p><a href="http://rubyforge.org/projects/random-word-gen/">And the Rubyforge site</a></p>
<p>By the way, I did find an almost useful use for this gem. Activation code generator. You know, the kind of string your receive on by email or SMS to activate a feature or an account. It&#8217;s always a pain to type a MD5Hash string, while, when using the word generator, the string is made of existing words, making the process way more user friendly.</p>
<p>I also plan on adding some random copyleft text to the sqlite db so the Gem will be able to generate titles, paragraphs and random quotes. I&#8217;m just tired of reading <a href="http://en.wikipedia.org/wiki/Lorem_ipsum">lorem ipsum</a> and on top of that, I get to it, I might had text in various languages so you check if your app breaks when using another char set, or if your layout can&#8217;t handle too much text.   </p>
<p>Honestly, I don&#8217;t expect you to use this gem, but I jut wanted to encourage people to start writing their own gem, the process is super easy and rewarding. And actually, feel free to try the challenge and post a link to your implementation in the comments. (That&#8217;s seriously, the best way to learn)</p>
<p>p.s: I&#8217;m sorry about my RSS feed constantly being reset, it seems to be a problem with Mephisto, my blog engine and we are trying to figure out what&#8217;s going on.</p>
]]></content:encoded>
			<wfw:commentRss>http://railsontherun.com/2007/12/04/a-new-useless-gem/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Ambition, why should you care?</title>
		<link>http://railsontherun.com/2007/09/16/ambition-why-should-you-care/</link>
		<comments>http://railsontherun.com/2007/09/16/ambition-why-should-you-care/#comments</comments>
		<pubDate>Sun, 16 Sep 2007 01:51:00 +0000</pubDate>
		<dc:creator>Matt Aimonetti</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[activeRecord]]></category>
		<category><![CDATA[ambition]]></category>
		<category><![CDATA[gem]]></category>
		<category><![CDATA[ORM]]></category>

		<guid isPermaLink="false">http://railsontherun.com/2007/09/24/ambition-why-should-you-care</guid>
		<description><![CDATA[
By now, you should have heard about ambition if not read the latest post from the author.
Ambition has a simple goal: making you stop writing SQL in your queries and only stick to Ruby. (who cares if you use ActiveRecord, Sequel, DataMapper or another ORM)
I&#8217;m so used to the ActiveRecord way of querying the database [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://errtheblog.com/static/images/ambition-tower.png" alt="ambition"/></p>
<p>By now, you should have heard about <a href="http://errtheblog.com/post/10722">ambition</a> if not <a href="http://errtheblog.com/post/11998">read the latest post from the author</a>.</p>
<p><strong>Ambition has a simple goal: making you stop writing SQL in your queries and only stick to Ruby. (who cares if you use ActiveRecord, Sequel, DataMapper or another ORM)</strong></p>
<p>I&#8217;m so used to the ActiveRecord way of querying the database that I was not fully convinced that Ambition would help me in my daily tasks. I still gave it a try: </p>
<h2>Testing Ambition</h2>
<pre><code>$ sudo gem install ambition -y
</code></pre>
<p>Started my console</p>
<pre><code>$ script/console
</code></pre>
<p>and required Ambition</p>
<pre><code>require 'ambition'
</code></pre>
<p>I started by doing a query the AR way:</p>
<table class="CodeRay">
<tr>
<td class="line_numbers" title="click to toggle" onclick="with (this.firstChild.style) { display = (display == '') ? 'none' : '' }">
<pre>1<tt>
</tt>2<tt>
</tt></pre>
</td>
<td class="code">
<pre ondblclick="with (this.style) { overflow = (overflow == 'auto' || overflow == '') ? 'visible' : 'auto' }"> <span class="co">Photo</span>.find(<span class="sy">:all</span>, <span class="sy">:conditions</span> =&gt; <span class="s"><span class="dl">&quot;</span><span class="k">photos.title IS NULL AND photos.width &gt; 250 <tt>
</tt>AND photos.height &gt; 200 AND users.name = 'test'</span><span class="dl">&quot;</span></span>, <span class="sy">:include</span> =&gt; <span class="sy">:user</span>) </pre>
</td>
</tr>
</table>
<p>And I converted it into an Ambition call:</p>
<table class="CodeRay">
<tr>
<td class="line_numbers" title="click to toggle" onclick="with (this.firstChild.style) { display = (display == '') ? 'none' : '' }">
<pre><tt>
</tt></pre>
</td>
<td class="code">
<pre ondblclick="with (this.style) { overflow = (overflow == 'auto' || overflow == '') ? 'visible' : 'auto' }"><span class="co">Photo</span>.select {|p| p.title == <span class="pc">nil</span> &amp;&amp; p.width &gt; <span class="i">250</span> &amp;&amp; p.height &gt; <span class="i">200</span>  &amp;&amp; p.user.name == <span class="s"><span class="dl">'</span><span class="k">test</span><span class="dl">'</span></span>}.entries</pre>
</td>
</tr>
</table>
<p>145 vs 102 keystrokes. 30% less typing with Ambition! I don&#8217;t know about you, but I REALLY prefer the Ruby only query, much cleaner and much &#8220;DRYer&#8221;. However, that&#8217;s not always true:</p>
<table class="CodeRay">
<tr>
<td class="line_numbers" title="click to toggle" onclick="with (this.firstChild.style) { display = (display == '') ? 'none' : '' }">
<pre><tt>
</tt></pre>
</td>
<td class="code">
<pre ondblclick="with (this.style) { overflow = (overflow == 'auto' || overflow == '') ? 'visible' : 'auto' }"><span class="co">Photo</span>.find_by_title(<span class="pc">nil</span>)</pre>
</td>
</tr>
</table>
<p>(24chars)<br />
<table class="CodeRay">
<tr>
<td class="line_numbers" title="click to toggle" onclick="with (this.firstChild.style) { display = (display == '') ? 'none' : '' }">
<pre><tt>
</tt></pre>
</td>
<td class="code">
<pre ondblclick="with (this.style) { overflow = (overflow == 'auto' || overflow == '') ? 'visible' : 'auto' }"><span class="co">Photo</span>.detect{|p| p.title == <span class="pc">nil</span>}</pre>
</td>
</tr>
</table>
<p> (32 chars)</p>
<p>But what&#8217;s going on behind the scene? Do we have the exact same SQL query sent to our DB?</p>
<p>Well, Ambition doesn&#8217;t generate any SQL, it uses AR to do so. You want to make sure Ambition is not messing with you, try that:</p>
<table class="CodeRay">
<tr>
<td class="line_numbers" title="click to toggle" onclick="with (this.firstChild.style) { display = (display == '') ? 'none' : '' }">
<pre>1<tt>
</tt>2<tt>
</tt></pre>
</td>
<td class="code">
<pre ondblclick="with (this.style) { overflow = (overflow == 'auto' || overflow == '') ? 'visible' : 'auto' }"> &gt;&gt; <span class="co">Photo</span>.select {|p| p.title == <span class="pc">nil</span> &amp;&amp; p.width &gt; <span class="i">250</span> &amp;&amp; p.height &gt; <span class="i">200</span>  &amp;&amp; p.user.name == <span class="s"><span class="dl">'</span><span class="k">test</span><span class="dl">'</span></span>}.to_hash<tt>
</tt> =&gt; {<span class="sy">:conditions</span>=&gt;<span class="s"><span class="dl">&quot;</span><span class="k">(photos.`title` IS NULL AND (photos.`width` &gt; 250 AND (photos.`height` &gt; 200 AND users.name = 'test')))</span><span class="dl">&quot;</span></span>, <span class="sy">:include</span>=&gt;[<span class="sy">:user</span>]}</pre>
</td>
</tr>
</table>
<p>That&#8217;s pretty hot. Especially when you have to use eager loading! </p>
<p>Obviously you can still do stuff like that:</p>
<table class="CodeRay">
<tr>
<td class="line_numbers" title="click to toggle" onclick="with (this.firstChild.style) { display = (display == '') ? 'none' : '' }">
<pre>1<tt>
</tt>2<tt>
</tt>3<tt>
</tt></pre>
</td>
<td class="code">
<pre ondblclick="with (this.style) { overflow = (overflow == 'auto' || overflow == '') ? 'visible' : 'auto' }"><span class="co">Photo</span>.select {|p| p.title == <span class="pc">nil</span> &amp;&amp; p.width &gt; <span class="i">250</span> &amp;&amp; p.height &gt; <span class="i">200</span>  &amp;&amp; p.user.name == <span class="s"><span class="dl">'</span><span class="k">test</span><span class="dl">'</span></span>}.each <span class="r">do</span> |photo|<tt>
</tt> puts photo.filename<tt>
</tt><span class="r">end</span></pre>
</td>
</tr>
</table>
<p>(note the query will only be made once)</p>
<p>Another cool thing, is to do simple sorting:</p>
<table class="CodeRay">
<tr>
<td class="line_numbers" title="click to toggle" onclick="with (this.firstChild.style) { display = (display == '') ? 'none' : '' }">
<pre><tt>
</tt></pre>
</td>
<td class="code">
<pre ondblclick="with (this.style) { overflow = (overflow == 'auto' || overflow == '') ? 'visible' : 'auto' }">&gt;&gt; <span class="co">Photo</span>.select {|p| p.title == <span class="pc">nil</span> &amp;&amp; p.user.name == <span class="s"><span class="dl">'</span><span class="k">test</span><span class="dl">'</span></span>}.sort_by { |p| [p.created_at, -p.size] }</pre>
</td>
</tr>
</table>
<p>creates the following:    </p>
<table class="CodeRay">
<tr>
<td class="line_numbers" title="click to toggle" onclick="with (this.firstChild.style) { display = (display == '') ? 'none' : '' }">
<pre><tt>
</tt></pre>
</td>
<td class="code">
<pre ondblclick="with (this.style) { overflow = (overflow == 'auto' || overflow == '') ? 'visible' : 'auto' }">=&gt; {<span class="sy"> <img src='http://railsontherun.com/wp-includes/images/smilies/icon_surprised.gif' alt=':o' class='wp-smiley' /> rder</span>=&gt;<span class="s"><span class="dl">&quot;</span><span class="k">photos.created_at, photos.size DESC</span><span class="dl">&quot;</span></span>, <span class="sy">:conditions</span>=&gt;<span class="s"><span class="dl">&quot;</span><span class="k">(photos.`title` IS NULL AND users.name = 'test')</span><span class="dl">&quot;</span></span>, <span class="sy">:include</span>=&gt;[<span class="sy">:user</span>]}</pre>
</td>
</tr>
</table>
<p>or    </p>
<table class="CodeRay">
<tr>
<td class="line_numbers" title="click to toggle" onclick="with (this.firstChild.style) { display = (display == '') ? 'none' : '' }">
<pre><tt>
</tt></pre>
</td>
<td class="code">
<pre ondblclick="with (this.style) { overflow = (overflow == 'auto' || overflow == '') ? 'visible' : 'auto' }">=&gt; <span class="s"><span class="dl">&quot;</span><span class="k">SELECT * FROM photos JOIN user WHERE (photos.`title` IS NULL AND users.name = 'test') ORDER BY photos.created_at, photos.size DESC</span><span class="dl">&quot;</span></span></pre>
</td>
</tr>
</table>
<p>That&#8217;s cool, and you can still sort on relationships:</p>
<table class="CodeRay">
<tr>
<td class="line_numbers" title="click to toggle" onclick="with (this.firstChild.style) { display = (display == '') ? 'none' : '' }">
<pre>1<tt>
</tt>2<tt>
</tt>3<tt>
</tt>4<tt>
</tt><strong>5</strong><tt>
</tt>6<tt>
</tt>7<tt>
</tt></pre>
</td>
<td class="code">
<pre ondblclick="with (this.style) { overflow = (overflow == 'auto' || overflow == '') ? 'visible' : 'auto' }">&gt;&gt; <span class="co">Photo</span>.select {|p| p.title == <span class="pc">nil</span> }.sort_by { |p| p.user.name }<tt>
</tt>=&gt; <span class="s"><span class="dl">&quot;</span><span class="k">SELECT * FROM photos JOIN user WHERE photos.`title` IS NULL ORDER BY users.name</span><span class="dl">&quot;</span></span>&lt;<span class="rx"><span class="dl">/</span><span class="k">macro:code &gt;<tt>
</tt>    <tt>
</tt>Or directly on the model:<tt>
</tt><tt>
</tt>&lt;macro:code lang=&quot;ruby&quot;&gt;&gt;&gt; Photo.sort_by(&amp;:title)<tt>
</tt>=&gt; &quot;SELECT * FROM photos ORDER BY photos.title&quot;</span></span></pre>
</td>
</tr>
</table>
<p>To finish, another detail which makes Ambition a great library</p>
<table class="CodeRay">
<tr>
<td class="line_numbers" title="click to toggle" onclick="with (this.firstChild.style) { display = (display == '') ? 'none' : '' }">
<pre>1<tt>
</tt>2<tt>
</tt>3<tt>
</tt></pre>
</td>
<td class="code">
<pre ondblclick="with (this.style) { overflow = (overflow == 'auto' || overflow == '') ? 'visible' : 'auto' }">&gt;&gt; <span class="co">Photo</span>.any? {|p| p.title =~ <span class="rx"><span class="dl">/</span><span class="k">ambition</span><span class="dl">/</span></span> }<tt>
</tt>=&gt; <span class="s"><span class="dl">&quot;</span><span class="k">SELECT count(*) AS count_all FROM photos WHERE (photos.`title` REGEXP 'ambition')</span><span class="dl">&quot;</span></span> <tt>
</tt>=&gt; <span class="pc">true</span></pre>
</td>
</tr>
</table>
<p>And if you were worried that it wouldn&#8217;t work with utf8, check this out:</p>
<table class="CodeRay">
<tr>
<td class="line_numbers" title="click to toggle" onclick="with (this.firstChild.style) { display = (display == '') ? 'none' : '' }">
<pre>1<tt>
</tt>2<tt>
</tt>3<tt>
</tt>4<tt>
</tt><strong>5</strong><tt>
</tt>6<tt>
</tt></pre>
</td>
<td class="code">
<pre ondblclick="with (this.style) { overflow = (overflow == 'auto' || overflow == '') ? 'visible' : 'auto' }">&gt;&gt; <span class="co">Photo</span>.any? {|p| p.title == <span class="s"><span class="dl">'</span><span class="k">Ã©cole</span><span class="dl">'</span></span>}<tt>
</tt>=&gt; <span class="co">SET</span> <span class="co">NAMES</span> <span class="s"><span class="dl">'</span><span class="k">utf8</span><span class="dl">'</span></span><tt>
</tt>=&gt; <span class="co">SET</span> <span class="co">SQL_AUTO_IS_NULL</span>=<span class="i">0</span><tt>
</tt>=&gt; <span class="co">SHOW</span> <span class="co">FIELDS</span> <span class="co">FROM</span> photos<tt>
</tt>=&gt; <span class="co">SELECT</span> count(*) <span class="co">AS</span> count_all <span class="co">FROM</span> photos <span class="co">WHERE</span> (photos.`title<span class="sh"><span class="dl">`</span><span class="k"> = 'Ã©cole') <tt>
</tt>=&gt; false</span></span></pre>
</td>
</tr>
</table>
<h2>Limitations</h2>
<p>The only limitation I found in Ambition is that Ruby code won&#8217;t work in the block, for instance:</p>
<table class="CodeRay">
<tr>
<td class="line_numbers" title="click to toggle" onclick="with (this.firstChild.style) { display = (display == '') ? 'none' : '' }">
<pre><tt>
</tt></pre>
</td>
<td class="code">
<pre ondblclick="with (this.style) { overflow = (overflow == 'auto' || overflow == '') ? 'visible' : 'auto' }">&gt;&gt; <span class="co">Photo</span>.select {|p| p.title == <span class="pc">nil</span> &amp;&amp; p.created_at &lt; <span class="i">1</span>.week.ago &amp;&amp; p.user.name == <span class="s"><span class="dl">'</span><span class="k">test</span><span class="dl">'</span></span>}.entries</pre>
</td>
</tr>
</table>
<p>won&#8217;t work at the moment. To inspect what&#8217;s going simply try:</p>
<table class="CodeRay">
<tr>
<td class="line_numbers" title="click to toggle" onclick="with (this.firstChild.style) { display = (display == '') ? 'none' : '' }">
<pre>1<tt>
</tt>2<tt>
</tt></pre>
</td>
<td class="code">
<pre ondblclick="with (this.style) { overflow = (overflow == 'auto' || overflow == '') ? 'visible' : 'auto' }">&gt;&gt; <span class="co">Photo</span>.select {|p| p.title == <span class="pc">nil</span> &amp;&amp; p.created_at &lt; <span class="i">1</span>.week.ago &amp;&amp; p.user.name == <span class="s"><span class="dl">'</span><span class="k">test</span><span class="dl">'</span></span>}.to_sql<tt>
</tt>=&gt; <span class="s"><span class="dl">&quot;</span><span class="k">SELECT * FROM photos JOIN user WHERE (photos.`title` IS NULL AND (photos.`created_at` &lt; 1.`week`.`ago` AND users.name = 'test'))</span><span class="dl">&quot;</span></span></pre>
</td>
</tr>
</table>
<p>You can see that <strong>photos.<code>created_at</code> &lt; 1.<code>week</code>.<code>ago</code></strong>  is the problem.</p>
<p>The recommended way to achieve the same result is to use variables:</p>
<table class="CodeRay">
<tr>
<td class="line_numbers" title="click to toggle" onclick="with (this.firstChild.style) { display = (display == '') ? 'none' : '' }">
<pre>1<tt>
</tt>2<tt>
</tt>3<tt>
</tt></pre>
</td>
<td class="code">
<pre ondblclick="with (this.style) { overflow = (overflow == 'auto' || overflow == '') ? 'visible' : 'auto' }">&gt;&gt; date = <span class="i">1</span>.week.ago<tt>
</tt>&gt;&gt; <span class="co">Photo</span>.select {|p| p.title == <span class="pc">nil</span> &amp;&amp; p.created_at &lt; date &amp;&amp; p.user.name == <span class="s"><span class="dl">'</span><span class="k">test</span><span class="dl">'</span></span>}.to_sql<tt>
</tt>=&gt; <span class="s"><span class="dl">&quot;</span><span class="k">SELECT * FROM photos JOIN user WHERE (photos.`title` IS NULL AND (photos.`created_at` &lt; '2007-09-08 19:38:48' AND users.name = 'test'))</span><span class="dl">&quot;</span></span></pre>
</td>
</tr>
</table>
<p>However, note that method calls will work just fine:</p>
<table class="CodeRay">
<tr>
<td class="line_numbers" title="click to toggle" onclick="with (this.firstChild.style) { display = (display == '') ? 'none' : '' }">
<pre>1<tt>
</tt>2<tt>
</tt>3<tt>
</tt>4<tt>
</tt><strong>5</strong><tt>
</tt>6<tt>
</tt></pre>
</td>
<td class="code">
<pre ondblclick="with (this.style) { overflow = (overflow == 'auto' || overflow == '') ? 'visible' : 'auto' }">&gt;&gt; <span class="r">def</span> <span class="fu">time_now_please</span><tt>
</tt>&gt;&gt; <span class="co">Time</span>.now<tt>
</tt>&gt;&gt; <span class="r">end</span><tt>
</tt>    <tt>
</tt>&gt;&gt; <span class="co">Photo</span>.select {|p| p.title == <span class="pc">nil</span> &amp;&amp; p.created_at &lt; time_now_please &amp;&amp; p.user.name == <span class="s"><span class="dl">'</span><span class="k">test</span><span class="dl">'</span></span>}.to_sql<tt>
</tt>=&gt; <span class="s"><span class="dl">&quot;</span><span class="k">SELECT * FROM photos JOIN user WHERE (photos.`title` IS NULL AND (photos.`created_at` &lt; '2007-09-15 19:41:37' AND users.name = 'test'))</span><span class="dl">&quot;</span></span>   </pre>
</td>
</tr>
</table>
<h2>Conclusion</h2>
<p>For now, Ambition is still just wrapping ActiveRecord::Base#find but the plan is to actually generate SQL. Hopefully we&#8217;ll also be able to use Ruby code from within an Ambition block. Kickers methods are very interesting and could become a really nice way of speeding up your app and keep your code clean.</p>
<p>Ambition is a great query library, I think I&#8217;ll start using it whenever I have &#8220;find&#8221; calls with multiple conditions especially if my conditions are related to another model. However I still didn&#8217;t figure out how to use an inner join with Ambition.</p>
]]></content:encoded>
			<wfw:commentRss>http://railsontherun.com/2007/09/16/ambition-why-should-you-care/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

