<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><!-- generator="wordpress/2.1.2" --><rss 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/" version="2.0">

<channel>
	<title>Ruby Fleebie</title>
	<link>http://www.rubyfleebie.com</link>
	<description>Because programming should be fun</description>
	<pubDate>Sun, 21 Mar 2010 01:23:44 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.1.2</generator>
	<language>en</language>
			<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/rubyfleebie" /><feedburner:info xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" uri="rubyfleebie" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><feedburner:emailServiceId xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0">rubyfleebie</feedburner:emailServiceId><feedburner:feedburnerHostname xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0">http://feedburner.google.com</feedburner:feedburnerHostname><item>
		<title>Last deployment date with Rails and Capistrano</title>
		<link>http://www.rubyfleebie.com/last-deployment-date/</link>
		<comments>http://www.rubyfleebie.com/last-deployment-date/#comments</comments>
		<pubDate>Fri, 19 Mar 2010 14:49:00 +0000</pubDate>
		<dc:creator>Frank</dc:creator>
		
		<category><![CDATA[short &amp; sweet]]></category>

		<guid isPermaLink="false">http://www.rubyfleebie.com/last-deployment-date/</guid>
		<description><![CDATA[When you are developing an app or a website for your client, it is pretty common to setup a sandbox environment where your client can test and see the application while it is still in development. One thing I find useful is to display the last deployment date on the home page.
Here is a quick [...]]]></description>
			<content:encoded><![CDATA[<p>When you are developing an app or a website for your client, it is pretty common to setup a sandbox environment where your client can test and see the application while it is still in development. One thing I find useful is to display the last deployment date on the home page.</p>
<p>Here is a quick and easy way to automate the process :</p>
<p><strong>Step #1 (we can have lots of fun)</strong><br />
I will consider that you use capistrano for deploying your app. The only thing you have to do in your capistrano recipe is to &#8220;touch&#8221; a dummy file to update its modification date.</p>
<pre lang='ruby'>
namespace :deploy do
  desc 'Restart My App'
  task :restart, :roles => :app do
    run "touch #{current_path}/last_deploy"
  end
end
</pre>
<p><strong>Step #2 (there&#8217;s so much we can do)</strong><br />
Now in application_controller, add a before_filter like this</p>
<pre lang='ruby'>
before_filter :last_deploy

def last_deploy
  @last_deploy = File.new("last_deploy").atime rescue Time.now
end
</pre>
<p><strong>Step #3 (it&#8217;s just you and me)</strong><br />
Display the date in the layout or in the view of your choice</p>
<pre lang='ruby'>
<%= "Last deployment : #{@last_deploy}"%>
</pre>
<p>Edit : Oh, dear readers, I just want to let you know that RubyFleebie is now on <a href="http://twitter.com/rubyfleebie">Twitter</a>.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/rubyfleebie?a=B9WYeMZnjus:VJUy78nNno8:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/rubyfleebie?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/rubyfleebie?a=B9WYeMZnjus:VJUy78nNno8:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/rubyfleebie?i=B9WYeMZnjus:VJUy78nNno8:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/rubyfleebie?a=B9WYeMZnjus:VJUy78nNno8:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/rubyfleebie?i=B9WYeMZnjus:VJUy78nNno8:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/rubyfleebie?a=B9WYeMZnjus:VJUy78nNno8:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/rubyfleebie?i=B9WYeMZnjus:VJUy78nNno8:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/rubyfleebie?a=B9WYeMZnjus:VJUy78nNno8:Gu391qSwH_A"><img src="http://feeds.feedburner.com/~ff/rubyfleebie?d=Gu391qSwH_A" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/rubyfleebie?a=B9WYeMZnjus:VJUy78nNno8:I9og5sOYxJI"><img src="http://feeds.feedburner.com/~ff/rubyfleebie?d=I9og5sOYxJI" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://www.rubyfleebie.com/last-deployment-date/feed/</wfw:commentRss>
		</item>
		<item>
		<title>5 Plugins Or Gems You Could Not Live Without</title>
		<link>http://www.rubyfleebie.com/5-plugins-or-gems-you-could-not-live-without/</link>
		<comments>http://www.rubyfleebie.com/5-plugins-or-gems-you-could-not-live-without/#comments</comments>
		<pubDate>Tue, 23 Feb 2010 14:50:51 +0000</pubDate>
		<dc:creator>Frank</dc:creator>
		
		<category><![CDATA[Easy reading]]></category>

		<guid isPermaLink="false">http://www.rubyfleebie.com/5-plugins-or-gems-you-could-not-live-without/</guid>
		<description><![CDATA[Hello everyone,
For the past few months this blog has been pretty much dead. I could give you tons of excuses as for why it has been so but that&#8217;s all they would be, mere excuses! And I assure you that you would not find any of them very convincing.
I received several comments recently telling me [...]]]></description>
			<content:encoded><![CDATA[<p>Hello everyone,</p>
<p>For the past few months this blog has been pretty much dead. I could give you tons of excuses as for why it has been so but that&#8217;s all they would be, mere excuses! And I assure you that you would not find any of them very convincing.</p>
<p>I received several comments recently telling me that you liked my blog and asking me when I plan writing again and believe me, it always goes straight to my heart. For some time now I am in the expectation that most of you will give up on me and remove this blog from your list forever but for some reason&#8230; you don&#8217;t! </p>
<p>Since I am a bit rusty at writing blog posts, I chose the easy way : a numbered list of Rails Gems/Plugins that I like. Hmmm, I know&#8230; it&#8217;s soooooo 2007! But, interesting nonetheless. If you don&#8217;t mind, I&#8217;d like that you share in the comment section the plugins that you like the most as well. Perhaps this post could become a reference to discover great plugins. Oh btw, from now on I will use the terms plugins and gems like they were the same thing.</p>
<ol>
<li><a href="http://github.com/thoughtbot/paperclip">Paperclip</a> by Thoughtbot
<p><em>Very easy to install &#038; configure. I use it for thumbnails generation and it works wonder.</em> </p>
</li>
<li><a href="http://github.com/perfectline/locale_routing">locale_routing</a> by Perfectline
<p><em>If you are developing a multilingual app/website (with I18n), don&#8217;t miss this simple plugin. It auto inserts the locale in the url without messing with your routes. </em></p>
</li>
<li><a href="http://freelancing-god.github.com/ts/en/">thinking-sphinx</a> by freelancing-gods
<p><em>A fast and reliable free-text search solution for your rails apps, using the Sphinx daemon.  The only thing that is really unfortunate with sphinx is that is doesn&#8217;t index new database records <strong>live</strong> out of the box. Instead you have to build the index manually or setup a cronjob at a given interval. The workaround is to use delta indexes with the delayed-job plugin but it forces you to have a rake task always running on your server. I had so much problems with the rake task getting killed for no apparent reason that I decided that live indexing was not so important. Instead I have a cronjob running every X hours that rebuild the index from scratch</em></p>
</li>
<li><a href="http://wiki.github.com/mislav/will_paginate/">will_paginate</a> by mislav
<p><em>I guess we all know and use this one but I had to put it in my list anyway. It is such a great and easy to use pagination plugin.</em></p>
</li>
<li><a href="http://github.com/rubyist/aasm">acts_as_state_machine</a> by rubyist</li>
<p><em>This one I use all the time. Everytime an activerecord object can be in more than a single &#8220;state&#8221; (enabled, hidden, locked, whatever)&#8230; think about using it!</em></p>
</ol>
<p>That&#8217;s it! Now, it&#8217;s your turn : what is your own top 5 list?</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/rubyfleebie?a=SK0Cx4WRjVs:93F0puZk5hA:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/rubyfleebie?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/rubyfleebie?a=SK0Cx4WRjVs:93F0puZk5hA:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/rubyfleebie?i=SK0Cx4WRjVs:93F0puZk5hA:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/rubyfleebie?a=SK0Cx4WRjVs:93F0puZk5hA:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/rubyfleebie?i=SK0Cx4WRjVs:93F0puZk5hA:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/rubyfleebie?a=SK0Cx4WRjVs:93F0puZk5hA:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/rubyfleebie?i=SK0Cx4WRjVs:93F0puZk5hA:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/rubyfleebie?a=SK0Cx4WRjVs:93F0puZk5hA:Gu391qSwH_A"><img src="http://feeds.feedburner.com/~ff/rubyfleebie?d=Gu391qSwH_A" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/rubyfleebie?a=SK0Cx4WRjVs:93F0puZk5hA:I9og5sOYxJI"><img src="http://feeds.feedburner.com/~ff/rubyfleebie?d=I9og5sOYxJI" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://www.rubyfleebie.com/5-plugins-or-gems-you-could-not-live-without/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Try Monit to manage your daemons</title>
		<link>http://www.rubyfleebie.com/try-monit-to-manage-your-daemons/</link>
		<comments>http://www.rubyfleebie.com/try-monit-to-manage-your-daemons/#comments</comments>
		<pubDate>Thu, 10 Sep 2009 19:14:07 +0000</pubDate>
		<dc:creator>Frank</dc:creator>
		
		<category><![CDATA[short &amp; sweet]]></category>

		<guid isPermaLink="false">http://www.rubyfleebie.com/try-monit-to-manage-your-daemons/</guid>
		<description><![CDATA[Hello there,
I&#8217;m sorry for not updating my blog more often. Now is the time to use the best excuse in the world that will make me look like a busy businessman and you will all be impressed. Here we go : I don&#8217;t have the time!
I know a lot of you are using GOD to [...]]]></description>
			<content:encoded><![CDATA[<p>Hello there,</p>
<p>I&#8217;m sorry for not updating my blog more often. Now is the time to use the best excuse in the world that will make me look like a busy businessman and you will all be impressed. Here we go : I don&#8217;t have the time!</p>
<p>I know a lot of you are using <a href="http://god.rubyforge.org/">GOD</a> to keep your daemons / processes alive. I really don&#8217;t want to say bad things about GOD (I can&#8217;t because I never tried it)&#8230; <a href="http://blog.bradgessler.com/use-monit-with-rails-not-god">but I DID read some really nasty things about it</a> and somehow it convinced me to try an alternative : <a href="http://mmonit.com/">Monit</a>.</p>
<p>The biggest advantage with Monit is that it is written in C instead of ruby&#8230; so it doesn&#8217;t leak and it appears to be faster. It is also pretty easy to configure. Here is a very basic monit configuration file:</p>
<pre lang='shell'>
set daemon 60

set httpd port 2812 address localhost
     allow localhost 

check process my_process
  with pidfile /home/apps/someapp/my_process.pid
  start program = "/home/apps/someapp/my_process start"
  stop program = "/home/apps/someapp/my_process stop"
</pre>
<p>Then, you start the monit daemon by typing : <strong>monit</strong></p>
<p>It will poll the monit configuration file every minute (this is the <em>set daemon 60</em> part) and will restart &#8216;my_process&#8217; whenever it is not running. Of course this is an extremely simple use case and there are a lot more configuration options you can play with. Have a look at the <a href="http://mmonit.com/monit/documentation/monit.html">documentation</a> for more info.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/rubyfleebie?a=1WfTon-YOwE:H9Q6kQEnnmM:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/rubyfleebie?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/rubyfleebie?a=1WfTon-YOwE:H9Q6kQEnnmM:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/rubyfleebie?i=1WfTon-YOwE:H9Q6kQEnnmM:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/rubyfleebie?a=1WfTon-YOwE:H9Q6kQEnnmM:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/rubyfleebie?i=1WfTon-YOwE:H9Q6kQEnnmM:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/rubyfleebie?a=1WfTon-YOwE:H9Q6kQEnnmM:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/rubyfleebie?i=1WfTon-YOwE:H9Q6kQEnnmM:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/rubyfleebie?a=1WfTon-YOwE:H9Q6kQEnnmM:Gu391qSwH_A"><img src="http://feeds.feedburner.com/~ff/rubyfleebie?d=Gu391qSwH_A" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/rubyfleebie?a=1WfTon-YOwE:H9Q6kQEnnmM:I9og5sOYxJI"><img src="http://feeds.feedburner.com/~ff/rubyfleebie?d=I9og5sOYxJI" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://www.rubyfleebie.com/try-monit-to-manage-your-daemons/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Ruby and C : Part 1</title>
		<link>http://www.rubyfleebie.com/ruby-and-c-part-1/</link>
		<comments>http://www.rubyfleebie.com/ruby-and-c-part-1/#comments</comments>
		<pubDate>Mon, 23 Feb 2009 04:07:33 +0000</pubDate>
		<dc:creator>Frank</dc:creator>
		
		<category><![CDATA[In depth]]></category>

		<guid isPermaLink="false">http://www.rubyfleebie.com/ruby-and-c-part-1/</guid>
		<description><![CDATA[This first part aims at explaining how Ruby in the background is not Ruby anymore. In the next part I&#8217;m going to talk about HOW to bridge some existing C library with your ruby application.
As you might know already, the official ruby interpreter is written in pure C. This means that whenever you type a [...]]]></description>
			<content:encoded><![CDATA[<p>This first part aims at explaining how Ruby in the background is not Ruby anymore. In the next part I&#8217;m going to talk about HOW to bridge some existing C library with your ruby application.</p>
<p>As you might know already, the <a href="http://www.ruby-lang.org">official ruby interpreter</a> is written in pure C. This means that whenever you type a ruby instruction, the interpreter will call the corresponding C function for you. For example, if you do :</p>
<div class="ch_code_container" style="font-family: monospace;">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;">
<div style="font-family: 'Trebuchet MS', Arial, Verdana; font-weight: normal;">arr = <span style="color:#7b0303; font-weight:bold;">Array</span>.<span style="color:#3a27c9;">new</span></div>
</li>
</ol>
</div>
<p>Ruby will call a C function (probably rb_ary_new) and a C structure will be created to hold the content of <i>arr</i>. When you will try to access <i>arr</i> later in your code, the interpreter will use that same C structure.</p>
<h3>On the ruby side of things we say that everything is an object. On the C side of things we say that everything is a VALUE</h3>
<p>
You also already know that everything in ruby is an object. To represent this reality on the C side of things, a custom type (typedef) has been created and has been given the name of VALUE. This type is a pointer (well, in fact it is not really a pointer but we won&#8217;t go into this right now) that can reference any kind of data type. When C defines something as a VALUE, you know that it is dealing with something that either A) comes from the ruby side of things, B) will be returned to the ruby side of things or C) is usable on the ruby side of things in one way or another. In all other situations, C is just C and doesn&#8217;t need the VALUE data type. When you see C using VALUE, what you are really seeing is ruby from the inside, and ruby from the inside is an ugly beast. It is not pretty, not elegant, not easy, not cool and honestly not that interesting. The thing is, it can save you a lot of work if you want to bridge an existing C library into your ruby application instead of having to rewrite the whole thing in plain ruby. That, in part, is why it can be very useful to know a little bit of ruby&#8217;s ugly side.</p>
<p>Let&#8217;s move on. We said that VALUE was the C way to represent a ruby object. If you open one of the source file of the ruby interpreter (array.c, string.c, etc.), you will find that the word VALUE is used everywhere :</p>
<div class="ch_code_container" style="font-family: monospace;">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;">
<div style="font-family: 'Trebuchet MS', Arial, Verdana; font-weight: normal;">VALUE rb_do_stuff<span style="color: #66cc66;">&#40;</span>VALUE param1, VALUE param2<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;">
<div style="font-family: 'Trebuchet MS', Arial, Verdana; font-weight: normal;">&nbsp; VALUE some_variable;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;">
<div style="font-family: 'Trebuchet MS', Arial, Verdana; font-weight: normal;">&nbsp; <span style="color: #993333;">int</span> x;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;">
<div style="font-family: 'Trebuchet MS', Arial, Verdana; font-weight: normal;">&nbsp; <span style="color: #808080; font-style: italic;">//bla bla bla bla</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Trebuchet MS', Arial, Verdana; font-weight: normal;">&nbsp; <span style="color: #b1b100;">return</span> some_variable; </div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;">
<div style="font-family: 'Trebuchet MS', Arial, Verdana; font-weight: normal;"><span style="color: #66cc66;">&#125;</span></div>
</li>
</ol>
</div>
<p>Since everything in ruby is an object (or a VALUE), the C functions that are responsible of returning something ready to use on the ruby side of things <b>always have to return a VALUE</b>. If they would return something else (int, char, char *, long), ruby would complain because it can understand objects and only objects. </p>
<p>A Fixnum is not a <i>int</i>, it is a VALUE. A Bignum is not a <i>long</i>, it is a VALUE. A String is not a <i>char *</i>, it is a VALUE, and so on.</p>
<h3>VALUE is not really a pointer, you say?</h3>
<p>Ok the following is not really important for the sake of this post but if you&#8217;re curious it will interest you. I said earlier that VALUE wasn&#8217;t really a pointer. Time has come to explain what it is and why. <a href="http://www.ruby-doc.org/doxygen/1.8.4/ruby_8h-source.html#l00066">VALUE is in fact an <strong>unsigned long</strong></a>.</p>
<p>There is only one reason why VALUE is an unsigned long and not a pointer : efficiency.</p>
<p>Remember what a pointer is? It is a variable that contains an address to some structure in memory. It is perfect for complex objects like arrays, hashes and custom objects&#8230; but it is a bit overkill for more primitive objects like Fixnums, booleans (TrueClass and FalseClass instances) and nil (NilClass instance). Ruby inventor thought that <strong>it would be great if in some cases the VALUE object could BE the data instead of POINTING TO the data</strong>. I mean, why having a VALUE that points to a structure that contains an integer that contains the number 1 when you could simply have a VALUE that contains the number 1?</p>
<p>So instead of being a pointer, VALUE is an unsigned long that can contain either A) an address to some structure that contains the data or B) the data itself (immediate value).</p>
<p>The data in a VALUE is stored in such a way that it is possible to know if it contains an address to some structure in memory or an immediate value. Ingenious, ain&#8217;t it?</p>
<p>In my next post, I will try to explain how you can use the ugly side of ruby to bridge an existing C library into your ruby (or rubyonrails) application.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~f/rubyfleebie?a=cMAzPZfQ"><img src="http://feeds.feedburner.com/~f/rubyfleebie?d=41" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/rubyfleebie?a=8Lf7pkTI"><img src="http://feeds.feedburner.com/~f/rubyfleebie?i=8Lf7pkTI" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/rubyfleebie?a=e1vDKaco"><img src="http://feeds.feedburner.com/~f/rubyfleebie?i=e1vDKaco" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/rubyfleebie?a=nXSKlrmc"><img src="http://feeds.feedburner.com/~f/rubyfleebie?i=nXSKlrmc" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/rubyfleebie?a=V6znp9BR"><img src="http://feeds.feedburner.com/~f/rubyfleebie?d=308" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/rubyfleebie?a=fqaVIAtd"><img src="http://feeds.feedburner.com/~f/rubyfleebie?d=124" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://www.rubyfleebie.com/ruby-and-c-part-1/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Geany IN, Komodo OUT</title>
		<link>http://www.rubyfleebie.com/geany-in-komodo-out/</link>
		<comments>http://www.rubyfleebie.com/geany-in-komodo-out/#comments</comments>
		<pubDate>Tue, 17 Feb 2009 16:45:33 +0000</pubDate>
		<dc:creator>Frank</dc:creator>
		
		<category><![CDATA[short &amp; sweet]]></category>

		<guid isPermaLink="false">http://www.rubyfleebie.com/geany-in-komodo-out/</guid>
		<description><![CDATA[First of all, I&#8217;d like to deny the rumor that I am dead.
I&#8217;m struggling since day #1 to find a good code editor for ruby. Mac users are happy with their textmate&#8230; but what&#8217;s left for us linux users? I tried gedit, vim, scribes and eclipse (with the aptana plugin) but wasn&#8217;t happy enough with [...]]]></description>
			<content:encoded><![CDATA[<p>First of all, I&#8217;d like to deny the rumor that I am dead.</p>
<p>I&#8217;m struggling since day #1 to find a good code editor for ruby. Mac users are happy with their textmate&#8230; but what&#8217;s left for us linux users? I tried gedit, vim, scribes and eclipse (with the aptana plugin) but wasn&#8217;t happy enough with any of them. <a href="http://www.rubyfleebie.com/komodo-edit-a-great-editor-for-dynamic-languages/">I thought I found a real gem in Komodo edit</a>, but that&#8217;s just not doing it for me anymore. Komodo is a great editor but it is plagued with a huge problem : it is slow and unresponsive. Sometime you start typing code and you won&#8217;t see what you just typed on the screen. Wait a few seconds and boom, here is your code&#8230; full of typos. </p>
<p>Now that my honey moon with Komodo is over, I searched the web and found <a href="http://www.geany.org/Main/HomePage">Geany</a>, a light-weight code editor that works for linux and windows. I&#8217;m very satisfied with it so far. Instead of making a half-assed review of the editor, I think you should try it by yourself and decide if you like it or not.</p>
<p><strong>Off topic note :</strong></p>
<p>Those who liked the &#8220;in depth&#8221; posts I was doing in the early days of this blog might be disappointed with the kind of posts I&#8217;m doing now. I&#8217;m thinking about this for some time and I can say that <strong>I am planning to start writing like those early days</strong>. Why? Well, simply because I found it more enjoyable. The problem however is finding the time to write longer and more in-depth posts. I am currently quite busy with <a href="http://www.timmyontime.com">TimmyOnTime</a> <a href="http://www.azankatech.com">and</a> <a href="http://behindtheclock.timmyontime.com">other</a> <a href="http://github.com/flamontagne/xmppbot/">projects</a> so unfortunately RubyFleebie is suffering from it. I want to thank you for your patience&#8230; it amazes me that I still have all those subscribers and daily readers.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~f/rubyfleebie?a=9WX1WCuH"><img src="http://feeds.feedburner.com/~f/rubyfleebie?d=41" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/rubyfleebie?a=wDGjTCjM"><img src="http://feeds.feedburner.com/~f/rubyfleebie?i=wDGjTCjM" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/rubyfleebie?a=MDl7jZe9"><img src="http://feeds.feedburner.com/~f/rubyfleebie?i=MDl7jZe9" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/rubyfleebie?a=mALu9T8n"><img src="http://feeds.feedburner.com/~f/rubyfleebie?i=mALu9T8n" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/rubyfleebie?a=EGAQryVo"><img src="http://feeds.feedburner.com/~f/rubyfleebie?d=308" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/rubyfleebie?a=9yhHnOnf"><img src="http://feeds.feedburner.com/~f/rubyfleebie?d=124" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://www.rubyfleebie.com/geany-in-komodo-out/feed/</wfw:commentRss>
		</item>
		<item>
		<title>simplyglobal : A simple globalization plugin for Rails</title>
		<link>http://www.rubyfleebie.com/simplyglobal-a-simple-globalization-plugin-for-rails/</link>
		<comments>http://www.rubyfleebie.com/simplyglobal-a-simple-globalization-plugin-for-rails/#comments</comments>
		<pubDate>Thu, 30 Oct 2008 18:38:58 +0000</pubDate>
		<dc:creator>Dan</dc:creator>
		
		<category><![CDATA[Easy reading]]></category>

		<guid isPermaLink="false">http://www.rubyfleebie.com/simplyglobal-a-simple-globalization-plugin-for-rails/</guid>
		<description><![CDATA[   simplyglobal : A simple globalization plugin for Rails
The following is a guest post from Dan Simard
Sometimes, you have to reinvent the wheel. It&#8217;s really sad to say and you will probably hate me for saying that (and I know that you&#8217;ll do because I hate myself for it). I&#8217;ve written a new [...]]]></description>
			<content:encoded><![CDATA[<h1>   simplyglobal : A simple globalization plugin for Rails</h1>
<p><strong>The following is a guest post from Dan Simard</strong></p>
<p>Sometimes, you have to reinvent the wheel. It&#8217;s really sad to say and you will probably hate me for saying that (and I know that you&#8217;ll do because I hate myself for it). I&#8217;ve written <strong>a new globalization plugin for Rails</strong>.</p>
<h3>   Why did I reinvented the wheel?</h3>
<p>I searched and tried a lot of <a href="http://agilewebdevelopment.com/plugins/search?search=global" title="other globalisation plugins">other globalisation plugins</a>&#8230; and I really tried them. I spent hours with <a href="http://agilewebdevelopment.com/plugins/globalize" title="Globalize">Globalize</a>. It was just too much. I tried the <a href="http://rubyforge.org/projects/gettextlocalize/" title="gettext_Localize">gettext_Localize</a> that works with the <a href="http://www.gnu.org/software/gettext/" title="Gettext">good ol&#8217; gettext</a> command. Fuck it. Too complicated. It just didn&#8217;t fit my needs at all.</p>
<p>All I wanted was a wheel that you can put a wood-pole in the middle and then it could start spinning. I made one.</p>
<p>You can go on the <a href="http://code.google.com/p/simplyglobal/" title="simplyglobal project homepage">simplyglobal project homepage</a> to learn on to <a href="http://code.google.com/p/simplyglobal/wiki/Install" title="install it">install it</a> and <a href="http://code.google.com/p/simplyglobal/wiki/How" title="use it">use it</a>.</p>
<p>In fact, this is not really a globalization plugin because there&#8217;s no localization handling or anything that can look like it. The name should have been <strong>simplytranslated</strong> but I already created the project with the name <em>simplyglobal</em> and it was an hassle to change it.</p>
<h3>       How to install</h3>
<p><strong>1.</strong> Execute <em>./script/plugin install <a href="http://simplyglobal.googlecode.com/svn/trunk/simplyglobal" rel="nofollow">http://simplyglobal.googlecode.com/svn/trunk/simplyglobal</a></em><br />
<strong>2.</strong> Create a file named <em>simplyglobal.rb</em> in the <em>config/initializers</em> directory<br />
<strong>3.</strong> In <em>simplyglobal.rb</em>, create hashes of language<br />
Add the language hashes to the objectYou will end up with a file named <em>simplyglobal.rb</em> that looks like this :</p>
<div class="ch_code_container" style="font-family: monospace;">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;">
<div style="font-family: 'Trebuchet MS', Arial, Verdana; font-weight: normal;"><span style="color:#7b0303; font-style:normal;">#français</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;">
<div style="font-family: 'Trebuchet MS', Arial, Verdana; font-weight: normal;">fr = <span style="color:#3a27c9; font-weight:bold;">&#123;</span>    <span style="color:#996600;">&quot;hi&quot;</span> =&gt; <span style="color:#996600;">&quot;bonjour&quot;</span>,    <span style="color:#996600;">&quot;welcome&quot;</span> =&gt; <span style="color:#996600;">&quot;bienvenue&quot;</span>  <span style="color:#3a27c9; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;">
<div style="font-family: 'Trebuchet MS', Arial, Verdana; font-weight: normal;"><span style="color:#7b0303; font-style:normal;"># espanol</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;">
<div style="font-family: 'Trebuchet MS', Arial, Verdana; font-weight: normal;">es = <span style="color:#3a27c9; font-weight:bold;">&#123;</span>    <span style="color:#996600;">&quot;hi&quot;</span> =&gt; <span style="color:#996600;">&quot;hola&quot;</span>,    <span style="color:#996600;">&quot;welcome&quot;</span> =&gt; <span style="color:#996600;">&quot;bienvenida&quot;</span><span style="color:#3a27c9; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Trebuchet MS', Arial, Verdana; font-weight: normal;">SimplyGlobal.<span style="color:#3a27c9;">add_language_hash</span><span style="color:#3a27c9; font-weight:bold;">&#40;</span>:fr, fr<span style="color:#3a27c9; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;">
<div style="font-family: 'Trebuchet MS', Arial, Verdana; font-weight: normal;">SimplyGlobal.<span style="color:#3a27c9;">add_language_hash</span><span style="color:#3a27c9; font-weight:bold;">&#40;</span>:es, es<span style="color:#3a27c9; font-weight:bold;">&#41;</span></div>
</li>
</ol>
</div>
<p>In <strong>development</strong>, this file will be loaded every request. In <strong>production</strong>, it is loaded once.</p>
<h3>       How to use it with strings</h3>
<p>After you <a href="http://code.google.com/p/simplyglobal/wiki/Install" title="installed it">installed it</a>, you can use it in these various ways.</p>
<p>SimplyGlobal adds a <strong>t()</strong> method to all string objects that will return the translated string. Example, if you have defined a language hash that looks like this (<strong>note</strong> : normally, the languages hash are defined in <em>config/initializers/simplyglobal.rb</em> but I put it inline for the sake of the example) :</p>
<div class="ch_code_container" style="font-family: monospace;">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;">
<div style="font-family: 'Trebuchet MS', Arial, Verdana; font-weight: normal;">fr = <span style="color:#3a27c9; font-weight:bold;">&#123;</span><span style="color:#996600;">&quot;hi&quot;</span> =&gt; <span style="color:#996600;">&quot;bonjour&quot;</span><span style="color:#3a27c9; font-weight:bold;">&#125;</span> <span style="color:#7b0303; font-style:normal;"># Create the language hash</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;">
<div style="font-family: 'Trebuchet MS', Arial, Verdana; font-weight: normal;">SimplyGlobal.<span style="color:#3a27c9;">add_language_hash</span><span style="color:#3a27c9; font-weight:bold;">&#40;</span>:fr, fr<span style="color:#3a27c9; font-weight:bold;">&#41;</span> <span style="color:#7b0303; font-style:normal;"># Add the language hash to simplyglobal</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;">
<div style="font-family: 'Trebuchet MS', Arial, Verdana; font-weight: normal;">SimplyGlobal.<span style="color:#3a27c9;">locale</span> = :fr <span style="color:#7b0303; font-style:normal;"># Assigns the locale to use</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;">
<div style="font-family: 'Trebuchet MS', Arial, Verdana; font-weight: normal;"><span style="color:#996600;">&quot;hi&quot;</span>.<span style="color:#3a27c9;">t</span> <span style="color:#7b0303; font-style:normal;"># returns &quot;bonjour&quot;</span></div>
</li>
</ol>
</div>
<p>As simple as that!</p>
<p>You can use it like the <a href="http://www.ruby-doc.org/core/classes/String.html#M000785" title="% method">% method</a> of the String class.</p>
<div class="ch_code_container" style="font-family: monospace;">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;">
<div style="font-family: 'Trebuchet MS', Arial, Verdana; font-weight: normal;">fr = <span style="color:#3a27c9; font-weight:bold;">&#123;</span><span style="color:#996600;">&quot;hi %s%d&quot;</span> =&gt; <span style="color:#996600;">&quot;bonjour %s%d&quot;</span><span style="color:#3a27c9; font-weight:bold;">&#125;</span> <span style="color:#7b0303; font-style:normal;"># Create the language hash</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;">
<div style="font-family: 'Trebuchet MS', Arial, Verdana; font-weight: normal;">SimplyGlobal.<span style="color:#3a27c9;">add_language_hash</span><span style="color:#3a27c9; font-weight:bold;">&#40;</span>:fr, fr<span style="color:#3a27c9; font-weight:bold;">&#41;</span> <span style="color:#7b0303; font-style:normal;"># Add the language hash to simplyglobal</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;">
<div style="font-family: 'Trebuchet MS', Arial, Verdana; font-weight: normal;">SimplyGlobal.<span style="color:#3a27c9;">locale</span> = :fr <span style="color:#7b0303; font-style:normal;"># Assigns the locale to use</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;">
<div style="font-family: 'Trebuchet MS', Arial, Verdana; font-weight: normal;"><span style="color:#996600;">&quot;hi&quot;</span>.<span style="color:#3a27c9;">t</span><span style="color:#3a27c9; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;Johnny&quot;</span>, <span style="color:#3a27c9;">5</span><span style="color:#3a27c9; font-weight:bold;">&#41;</span> <span style="color:#7b0303; font-style:normal;"># returns &quot;bonjour Johnny5&quot;</span></div>
</li>
</ol>
</div>
<p>You can also return all translations for a word. That is a special feature developed only for Frank.</p>
<div class="ch_code_container" style="font-family: monospace;">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;">
<div style="font-family: 'Trebuchet MS', Arial, Verdana; font-weight: normal;">SimplyGlobal.<span style="color:#3a27c9;">add_language_hash</span><span style="color:#3a27c9; font-weight:bold;">&#40;</span>:fr, <span style="color:#3a27c9; font-weight:bold;">&#123;</span><span style="color:#996600;">&quot;hi&quot;</span> =&gt; <span style="color:#996600;">&quot;bonjour&quot;</span><span style="color:#3a27c9; font-weight:bold;">&#125;</span><span style="color:#3a27c9; font-weight:bold;">&#41;</span> <span style="color:#7b0303; font-style:normal;"># Add the french language hash</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;">
<div style="font-family: 'Trebuchet MS', Arial, Verdana; font-weight: normal;">SimplyGlobal.<span style="color:#3a27c9;">add_language_hash</span><span style="color:#3a27c9; font-weight:bold;">&#40;</span>:es, <span style="color:#3a27c9; font-weight:bold;">&#123;</span><span style="color:#996600;">&quot;hi&quot;</span> =&gt; <span style="color:#996600;">&quot;hola&quot;</span><span style="color:#3a27c9; font-weight:bold;">&#125;</span><span style="color:#3a27c9; font-weight:bold;">&#41;</span> <span style="color:#7b0303; font-style:normal;"># Add the spanish language hash</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;">
<div style="font-family: 'Trebuchet MS', Arial, Verdana; font-weight: normal;"><span style="color:#996600;">&quot;hi&quot;</span>.<span style="color:#3a27c9;">t</span><span style="color:#3a27c9; font-weight:bold;">&#40;</span>:all<span style="color:#3a27c9; font-weight:bold;">&#41;</span> <span style="color:#7b0303; font-style:normal;"># returns a hash : {:fr =&gt; &quot;bonjour&quot;, :es =&gt; &quot;hola&quot;}</span></div>
</li>
</ol>
</div>
<h3>       Using it with views</h3>
<p>Just create a view ending with <strong>_fr</strong> and simplyglobal will use it.</p>
<div class="ch_code_container" style="font-family: monospace;">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;">
<div style="font-family: 'Trebuchet MS', Arial, Verdana; font-weight: normal;"><span style="color:#3a27c9; font-weight:normal;">def</span> index</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;">
<div style="font-family: 'Trebuchet MS', Arial, Verdana; font-weight: normal;">&nbsp; SimplyGlobal.<span style="color:#3a27c9;">locale</span> = :fr</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;">
<div style="font-family: 'Trebuchet MS', Arial, Verdana; font-weight: normal;">&nbsp; <span style="color:#7b0303; font-style:normal;"># Will try to render index_fr.html.erb</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;">
<div style="font-family: 'Trebuchet MS', Arial, Verdana; font-weight: normal;">&nbsp; <span style="color:#7b0303; font-style:normal;"># rather than index.html.erb</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Trebuchet MS', Arial, Verdana; font-weight: normal;"><span style="color:#3a27c9; font-weight:normal;">end</span></div>
</li>
</ol>
</div>
<p>It also works for the partial.</p>
<div class="ch_code_container" style="font-family: monospace;">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;">
<div style="font-family: 'Trebuchet MS', Arial, Verdana; font-weight: normal;">&lt;%= render :partial =&gt; &quot;info&quot; %&gt;</div>
</li>
</ol>
</div>
<p>will try to render <strong>_info_fr.html.erb</strong> rather than <strong>_info.html.erb</strong>.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~f/rubyfleebie?a=k9rWFByZ"><img src="http://feeds.feedburner.com/~f/rubyfleebie?d=41" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/rubyfleebie?a=NsOxaZsr"><img src="http://feeds.feedburner.com/~f/rubyfleebie?i=NsOxaZsr" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/rubyfleebie?a=LdC9IVPx"><img src="http://feeds.feedburner.com/~f/rubyfleebie?i=LdC9IVPx" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/rubyfleebie?a=tCt8p1Pn"><img src="http://feeds.feedburner.com/~f/rubyfleebie?i=tCt8p1Pn" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/rubyfleebie?a=82Qp9HYV"><img src="http://feeds.feedburner.com/~f/rubyfleebie?d=308" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/rubyfleebie?a=32t00Ntk"><img src="http://feeds.feedburner.com/~f/rubyfleebie?d=124" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://www.rubyfleebie.com/simplyglobal-a-simple-globalization-plugin-for-rails/feed/</wfw:commentRss>
		</item>
		<item>
		<title>How to display a collection grouped by an attribute value in Rails</title>
		<link>http://www.rubyfleebie.com/how-to-display-a-collection-grouped-by-an-attribute-value-in-rails/</link>
		<comments>http://www.rubyfleebie.com/how-to-display-a-collection-grouped-by-an-attribute-value-in-rails/#comments</comments>
		<pubDate>Mon, 13 Oct 2008 19:44:32 +0000</pubDate>
		<dc:creator>Frank</dc:creator>
		
		<category><![CDATA[In depth]]></category>

		<guid isPermaLink="false">http://www.rubyfleebie.com/how-to-display-a-collection-grouped-by-an-attribute-value-in-rails/</guid>
		<description><![CDATA[Flashback time. We are in 1999 and you are coding in ASP... yet people are not laughing at you.]]></description>
			<content:encoded><![CDATA[<p>Flashback time. We are in 1999 and you are coding in ASP thinking that this language is the future. You use ADODB recordsets to iterate over collections. You have a recordset containing some records from a &#8220;quotes&#8221; table. The &#8220;quotes&#8221; table contains a author column (varchar) and a body column (varchar). Now you want to display the results grouped by author name so it looks like this : </p>
<p><strong>Georges Brassens</strong><br />
- Les filles quand ça dit &#8220;je t&#8217;aime&#8221;, c&#8217;est comme un second baptême<br />
- Aucune idée sur terre n&#8217;est digne d&#8217;un trépas</p>
<p><strong>Billie Holiday</strong><br />
- Don&#8217;t threaten me with love, baby. Let&#8217;s just go walking in the rain.<br />
- I never hurt nobody but myself and that&#8217;s nobody&#8217;s business but my own.</p>
<p>Assuming your recordset is ordered by author, you do something like this (remember, we&#8217;re in 1999) : </p>
<div class="ch_code_container" style="font-family: monospace;">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;">
<div style="font-family: 'Trebuchet MS', Arial, Verdana; font-weight: normal;">&lt;TABLE style=<span style="color: #ff0000;">&quot;color:fushia;font-style:MSONormal generated=frontpage&quot;</span>&gt;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;">
<div style="font-family: 'Trebuchet MS', Arial, Verdana; font-weight: normal;">&lt;%<span style="color: #b1b100;">while</span> <span style="color: #b1b100;">not</span> objRS.<span style="color: #b1b100;">eof</span> %&gt;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;">
<div style="font-family: 'Trebuchet MS', Arial, Verdana; font-weight: normal;">&lt;%<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>current_author &lt;&gt; objRS<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;author&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>%&gt;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;">
<div style="font-family: 'Trebuchet MS', Arial, Verdana; font-weight: normal;">&lt;h1&gt;&lt;%=objRS<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;author&quot;</span><span style="color: #66cc66;">&#41;</span>%&gt;&lt;/h1&gt;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Trebuchet MS', Arial, Verdana; font-weight: normal;">&lt;%<span style="color: #b1b100;">end</span> if%&gt;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;">
<div style="font-family: 'Trebuchet MS', Arial, Verdana; font-weight: normal;">&lt;Tr&gt;&lt;td&gt;&lt;%=objRS<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;body&quot;</span><span style="color: #66cc66;">&#41;</span>&lt;/td&gt;&lt;/TR&gt;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;">
<div style="font-family: 'Trebuchet MS', Arial, Verdana; font-weight: normal;">&lt;%current_author = objRS<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;author&quot;</span><span style="color: #66cc66;">&#41;</span>%&gt;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;">
<div style="font-family: 'Trebuchet MS', Arial, Verdana; font-weight: normal;">&lt;%objRS.<span style="color: #66cc66;">MoveNext</span>%&gt;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;">
<div style="font-family: 'Trebuchet MS', Arial, Verdana; font-weight: normal;">&lt;%loop%&gt;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Trebuchet MS', Arial, Verdana; font-weight: normal;">&lt;%objRS.<span style="color: #66cc66;">close</span>%&gt;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;">
<div style="font-family: 'Trebuchet MS', Arial, Verdana; font-weight: normal;">&lt;/TABLE&gt;</div>
</li>
</ol>
</div>
<p>Ok welcome back in 2008. ASP is dead. You are coding in rails and you want to do the same thing. How will you do it? Storing the author name in a buffer variable like in 1999? Not too sure about it.</p>
<p>This is a job for Enumerable#group_by (Enumerable is a <a href="http://www.rubyfleebie.com/an-introduction-to-modules-part-2">module</a> that is mixed in the Array class)</p>
<div class="ch_code_container" style="font-family: monospace;">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;">
<div style="font-family: 'Trebuchet MS', Arial, Verdana; font-weight: normal;">all_quotes = Quote.<span style="color:#3a27c9;">find</span><span style="color:#3a27c9; font-weight:bold;">&#40;</span>:all<span style="color:#3a27c9; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;">
<div style="font-family: 'Trebuchet MS', Arial, Verdana; font-weight: normal;">@authors = all_quotes.<span style="color:#3a27c9;">group_by</span><span style="color:#3a27c9; font-weight:bold;">&#40;</span>&amp;:author<span style="color:#3a27c9; font-weight:bold;">&#41;</span></div>
</li>
</ol>
</div>
<p>Enumerable#group_by will create different sets of quotes based on the &#8220;author&#8221; values. Why the &#8220;&#038;&#8221; sign? It&#8217;s because group_by expects a block. I could have done it this way  : @authors = all_quotes.group_by{|quote| quote.author}</p>
<p>So @authors is now a hash that will look like this:</p>
<p>{&#8221;George Brassens&#8221; => [#&lt;Quote id:131 &#8230;&gt;, #&lt;Quote id:331 &#8230;&gt;], &#8220;Billie Holiday&#8221; => [#&lt;Quote id:111 &#8230;&gt;, #&lt;Quote id:911 &#8230;&gt;] }</p>
<p>Now you can iterate over it like this :</p>
<div class="ch_code_container" style="font-family: monospace;">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;">
<div style="font-family: 'Trebuchet MS', Arial, Verdana; font-weight: normal;">@authors.<span style="color:#3a27c9;">each_pair</span> <span style="color:#3a27c9; font-weight:normal;">do</span> |author_name, quotes|</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;">
<div style="font-family: 'Trebuchet MS', Arial, Verdana; font-weight: normal;">&nbsp; &lt;h1&gt;&lt;%=author_name%&gt;&lt;/h1&gt;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;">
<div style="font-family: 'Trebuchet MS', Arial, Verdana; font-weight: normal;">&nbsp; &lt;%quotes.<span style="color:#3a27c9;">each</span> <span style="color:#3a27c9; font-weight:normal;">do</span> |quote| %&gt;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;">
<div style="font-family: 'Trebuchet MS', Arial, Verdana; font-weight: normal;">&nbsp; &nbsp; - &lt;%=quote.<span style="color:#3a27c9;">body</span>%&gt;&lt;br /&gt;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Trebuchet MS', Arial, Verdana; font-weight: normal;">&nbsp; &lt;%end%&gt;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;">
<div style="font-family: 'Trebuchet MS', Arial, Verdana; font-weight: normal;">&lt;%end%&gt;</div>
</li>
</ol>
</div>
<p>One more thing to note : @authors is a hash, and hashes cannot be ordered. If you want to display quotes by sorted author name, you could do this :</p>
<div class="ch_code_container" style="font-family: monospace;">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;">
<div style="font-family: 'Trebuchet MS', Arial, Verdana; font-weight: normal;">@authors.<span style="color:#3a27c9;">keys</span>.<span style="color:#3a27c9;">sort</span>.<span style="color:#3a27c9;">each</span> <span style="color:#3a27c9; font-weight:normal;">do</span> |author_name|</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;">
<div style="font-family: 'Trebuchet MS', Arial, Verdana; font-weight: normal;">&nbsp; &lt;h1&gt;&lt;%=author_name%&gt;&lt;/h1&gt;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;">
<div style="font-family: 'Trebuchet MS', Arial, Verdana; font-weight: normal;">&nbsp; &lt;%@authors<span style="color:#3a27c9; font-weight:bold;">&#91;</span>author_name<span style="color:#3a27c9; font-weight:bold;">&#93;</span>.<span style="color:#3a27c9;">each</span> <span style="color:#3a27c9; font-weight:normal;">do</span> |quote|%&gt;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;">
<div style="font-family: 'Trebuchet MS', Arial, Verdana; font-weight: normal;">&nbsp; &nbsp; - &lt;%=quote.<span style="color:#3a27c9;">body</span>%&gt;&lt;br /&gt;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Trebuchet MS', Arial, Verdana; font-weight: normal;">&nbsp; &lt;%end%&gt;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;">
<div style="font-family: 'Trebuchet MS', Arial, Verdana; font-weight: normal;">&lt;%end%&gt;</div>
</li>
</ol>
</div>
<p>Note : Enumerable#group_by does not exist in ruby 1.8, it only exists in Rails. The method will be in ruby 1.9 however.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~f/rubyfleebie?a=E9p8WEcT"><img src="http://feeds.feedburner.com/~f/rubyfleebie?d=41" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/rubyfleebie?a=T0iBBXc0"><img src="http://feeds.feedburner.com/~f/rubyfleebie?i=T0iBBXc0" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/rubyfleebie?a=tuHeRIim"><img src="http://feeds.feedburner.com/~f/rubyfleebie?i=tuHeRIim" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/rubyfleebie?a=ieThyF8Q"><img src="http://feeds.feedburner.com/~f/rubyfleebie?i=ieThyF8Q" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/rubyfleebie?a=E1usldOP"><img src="http://feeds.feedburner.com/~f/rubyfleebie?d=308" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/rubyfleebie?a=HSwuKGDY"><img src="http://feeds.feedburner.com/~f/rubyfleebie?d=124" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://www.rubyfleebie.com/how-to-display-a-collection-grouped-by-an-attribute-value-in-rails/feed/</wfw:commentRss>
		</item>
		<item>
		<title>XMPP4r 0.4 has been released</title>
		<link>http://www.rubyfleebie.com/xmpp4r-04-has-been-released/</link>
		<comments>http://www.rubyfleebie.com/xmpp4r-04-has-been-released/#comments</comments>
		<pubDate>Tue, 07 Oct 2008 13:54:25 +0000</pubDate>
		<dc:creator>Frank</dc:creator>
		
		<category><![CDATA[Easy reading]]></category>

		<guid isPermaLink="false">http://www.rubyfleebie.com/xmpp4r-04-has-been-released/</guid>
		<description><![CDATA[It&#8217;s been a while since the latest release of XMPP4r. I was starting to think that the development for this great library had been stopped.
Fortunately, version 0.4 has been released on August 5th 2008. We&#8217;re going to try this new version internally and eventually use it for TimmyOnTime. I am personnally hoping for less memory [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s been a while since the latest release of <a href="http://home.gna.org/xmpp4r/">XMPP4r</a>. I was starting to think that the development for this great library had been stopped.</p>
<p>Fortunately, version 0.4 has been released on August 5th 2008. We&#8217;re going to try this new version internally and eventually use it for TimmyOnTime. I am personnally hoping for less memory consumption, more speed and more stability. This new version highlights are : </p>
<ol>
<li>The beginning of ruby 1.9 support</li>
<li>Refactoring of error classes (I&#8217;m really looking forward to this)</li>
</ol>
<p>Here is the full changelog :</p>
<p>XMPP4R 0.4 (05/08/2008)<br />
=======================<br />
* Initial support for Ruby 1.9 (see README_ruby19.txt)<br />
* Complete PubSub API Change - more logical and better for<br />
  childclasses, support for collection node creation<br />
* a Helper to assist with XEP-0115 Entity Capabilities<br />
* SASL anonymous support<br />
* File transfer fixes<br />
* MUC room configuration fixes<br />
* initial support for XEP-0118 User Tune<br />
* fix for an xmlrpc exception-during-serialisation bug, which would cause<br />
  a hang<br />
* Support auto-gem generation on GitHub with improved and DRY&#8217;er RakeFile and<br />
  gemspec.<br />
* Add support for the old SSL protocol (needed to connect to GTalk)<br />
* Changed API for Client, Component, Connection, Stream to remove<br />
  need for antiquated &#8216;threaded&#8217; param in the initializer.<br />
* Use a Logger instance instead of directly writing to stdout<br />
* Re-factored &#038; consolidated Error classes.  See xmpp4r/errors.rb for all<br />
  custom errors that can be caught.  All inherit from Jabber::Error which<br />
  itself inherits from Ruby&#8217;s StandardError. This is a first step in<br />
  re-factoring errors.  The next step will be to convert all &#8216;raise&#8217; calls to<br />
  raise a custom Jabber::Error or one of its children instead of anonymous<br />
  RuntimeErrors.  This allows much more granularity in catching and handling<br />
  errors later.<br />
  If you were catching Jabber::ErrorException before you should probably<br />
  change that in your code to now catch Jabber::Error if you want to<br />
  catch everything or one of the custom children of Jabber::Error defined in<br />
  &#8216;lib/xmpp4r/errors.rb&#8217;.  Additionally, the Error class which encapsulated<br />
  the xmpp error response, has been renamed to ErrorResponse to reflect its<br />
  real usage.  This free&#8217;s up &#8216;Jabber::Error&#8217; for use as our base Error class.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~f/rubyfleebie?a=giOBol9I"><img src="http://feeds.feedburner.com/~f/rubyfleebie?d=41" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/rubyfleebie?a=gfZQTI0e"><img src="http://feeds.feedburner.com/~f/rubyfleebie?i=gfZQTI0e" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/rubyfleebie?a=hiN2HnGZ"><img src="http://feeds.feedburner.com/~f/rubyfleebie?i=hiN2HnGZ" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/rubyfleebie?a=1lXhWiWf"><img src="http://feeds.feedburner.com/~f/rubyfleebie?i=1lXhWiWf" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/rubyfleebie?a=vFriaSPa"><img src="http://feeds.feedburner.com/~f/rubyfleebie?d=308" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/rubyfleebie?a=UVIX1ZOz"><img src="http://feeds.feedburner.com/~f/rubyfleebie?d=124" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://www.rubyfleebie.com/xmpp4r-04-has-been-released/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Get the intersection of 2 arrays</title>
		<link>http://www.rubyfleebie.com/get-the-intersection-of-2-arrays/</link>
		<comments>http://www.rubyfleebie.com/get-the-intersection-of-2-arrays/#comments</comments>
		<pubDate>Fri, 03 Oct 2008 21:39:25 +0000</pubDate>
		<dc:creator>Frank</dc:creator>
		
		<category><![CDATA[short &amp; sweet]]></category>

		<guid isPermaLink="false">http://www.rubyfleebie.com/get-the-intersection-of-2-arrays/</guid>
		<description><![CDATA[Pretty easy stuff today, but this is not something you may need to do often so maybe you don&#8217;t know how to do it.
Say I have these 2 arrays :



colors1 = &#91;:blue, :red, :green, :orange, :purple&#93;


colors2 = &#91;:yellow, :cyan, :green, :blue, :purple&#93;



Now what if I want a new array that contains only the elements present [...]]]></description>
			<content:encoded><![CDATA[<p>Pretty easy stuff today, but this is not something you may need to do often so maybe you don&#8217;t know how to do it.</p>
<p>Say I have these 2 arrays :</p>
<div class="ch_code_container" style="font-family: monospace;">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;">
<div style="font-family: 'Trebuchet MS', Arial, Verdana; font-weight: normal;">colors1 = <span style="color:#3a27c9; font-weight:bold;">&#91;</span>:blue, :red, :green, :orange, :purple<span style="color:#3a27c9; font-weight:bold;">&#93;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;">
<div style="font-family: 'Trebuchet MS', Arial, Verdana; font-weight: normal;">colors2 = <span style="color:#3a27c9; font-weight:bold;">&#91;</span>:yellow, :cyan, :green, :blue, :purple<span style="color:#3a27c9; font-weight:bold;">&#93;</span></div>
</li>
</ol>
</div>
<p>Now what if I want a new array that contains only the elements present in both arrays?</p>
<div class="ch_code_container" style="font-family: monospace;">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;">
<div style="font-family: 'Trebuchet MS', Arial, Verdana; font-weight: normal;">beautiful_colors = colors1 &amp; colors2</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;">
<div style="font-family: 'Trebuchet MS', Arial, Verdana; font-weight: normal;"><span style="color:#7b0303; font-style:normal;">#beautiful_colors contains [:blue, :green, :purple]</span></div>
</li>
</ol>
</div>
<p>Have a nice weekend!</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~f/rubyfleebie?a=nRax6vGS"><img src="http://feeds.feedburner.com/~f/rubyfleebie?d=41" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/rubyfleebie?a=QMMi7HWB"><img src="http://feeds.feedburner.com/~f/rubyfleebie?i=QMMi7HWB" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/rubyfleebie?a=y0lQ8nuF"><img src="http://feeds.feedburner.com/~f/rubyfleebie?i=y0lQ8nuF" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/rubyfleebie?a=lmPFmhSg"><img src="http://feeds.feedburner.com/~f/rubyfleebie?i=lmPFmhSg" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/rubyfleebie?a=gKoe6fRR"><img src="http://feeds.feedburner.com/~f/rubyfleebie?d=308" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/rubyfleebie?a=23xqobW8"><img src="http://feeds.feedburner.com/~f/rubyfleebie?d=124" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://www.rubyfleebie.com/get-the-intersection-of-2-arrays/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Need support for has_many through with has_one in the “bridge table”</title>
		<link>http://www.rubyfleebie.com/need-support-for-has_many-through-with-has_one-in-the-bridge-table/</link>
		<comments>http://www.rubyfleebie.com/need-support-for-has_many-through-with-has_one-in-the-bridge-table/#comments</comments>
		<pubDate>Sat, 13 Sep 2008 18:02:51 +0000</pubDate>
		<dc:creator>Frank</dc:creator>
		
		<category><![CDATA[short &amp; sweet]]></category>

		<guid isPermaLink="false">http://www.rubyfleebie.com/need-support-for-has_many-through-with-has_one-in-the-bridge-table/</guid>
		<description><![CDATA[has_many :through limitations]]></description>
			<content:encoded><![CDATA[<p>Let me expose the problem with an example :</p>
<p>Cart model (as in : shopping cart)</p>
<div class="ch_code_container" style="font-family: monospace;">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;">
<div style="font-family: 'Trebuchet MS', Arial, Verdana; font-weight: normal;"><span style="color:#3a27c9; font-weight:normal;">class</span> Cart &lt; ActiveRecord::Base</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;">
<div style="font-family: 'Trebuchet MS', Arial, Verdana; font-weight: normal;">&nbsp; has_one :bill</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;">
<div style="font-family: 'Trebuchet MS', Arial, Verdana; font-weight: normal;">&nbsp; belongs_to :user</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;">
<div style="font-family: 'Trebuchet MS', Arial, Verdana; font-weight: normal;"><span style="color:#3a27c9; font-weight:normal;">end</span></div>
</li>
</ol>
</div>
<p>Bill model</p>
<div class="ch_code_container" style="font-family: monospace;">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;">
<div style="font-family: 'Trebuchet MS', Arial, Verdana; font-weight: normal;"><span style="color:#3a27c9; font-weight:normal;">class</span> Bill &lt; ActiveRecord::Base</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;">
<div style="font-family: 'Trebuchet MS', Arial, Verdana; font-weight: normal;">&nbsp; belongs_to :cart&nbsp; </div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;">
<div style="font-family: 'Trebuchet MS', Arial, Verdana; font-weight: normal;"><span style="color:#3a27c9; font-weight:normal;">end</span></div>
</li>
</ol>
</div>
<p>User</p>
<div class="ch_code_container" style="font-family: monospace;">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;">
<div style="font-family: 'Trebuchet MS', Arial, Verdana; font-weight: normal;"><span style="color:#3a27c9; font-weight:normal;">class</span> User &lt; ActiveRecord::Base</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;">
<div style="font-family: 'Trebuchet MS', Arial, Verdana; font-weight: normal;">&nbsp; has_many :carts</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;">
<div style="font-family: 'Trebuchet MS', Arial, Verdana; font-weight: normal;">&nbsp; has_many :bills, :through =&gt; :carts <span style="color:#7b0303; font-style:normal;">#&lt;== Doesn&#8217;t work&#8230; no user.bills for you!</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;">
<div style="font-family: 'Trebuchet MS', Arial, Verdana; font-weight: normal;"><span style="color:#3a27c9; font-weight:normal;">end</span></div>
</li>
</ol>
</div>
<p>Basically, because the &#8220;through&#8221; table links the destination table with a has_one relationship, ActiveRecord complains with : <em>Invalid source reflection macro :has_one for has_many :bills, :through => :carts.  Use :source to specify the source reflection.</em></p>
<p>Someone on Rails Trac already created a <a href="http://dev.rubyonrails.org/ticket/4996">ticket</a> about this issue <strong>2 years ago</strong>. Can we expect this feature to be officially supported in the future? Let&#8217;s hope so.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~f/rubyfleebie?a=drLiKcv8"><img src="http://feeds.feedburner.com/~f/rubyfleebie?d=41" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/rubyfleebie?a=gbLxQ3yy"><img src="http://feeds.feedburner.com/~f/rubyfleebie?i=gbLxQ3yy" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/rubyfleebie?a=C6kwjl1Z"><img src="http://feeds.feedburner.com/~f/rubyfleebie?i=C6kwjl1Z" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/rubyfleebie?a=nxSpR5Oz"><img src="http://feeds.feedburner.com/~f/rubyfleebie?i=nxSpR5Oz" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/rubyfleebie?a=Qtk0jCZv"><img src="http://feeds.feedburner.com/~f/rubyfleebie?d=308" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/rubyfleebie?a=h2NOm2fo"><img src="http://feeds.feedburner.com/~f/rubyfleebie?d=124" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://www.rubyfleebie.com/need-support-for-has_many-through-with-has_one-in-the-bridge-table/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
