<?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"?><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/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>Buci on Rails</title>
	
	<link>http://bucionrails.com</link>
	<description>Ruby, Rails, TDD, programming</description>
	<pubDate>Tue, 14 Jul 2009 16:49:51 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.5</generator>
	<language>en</language>
			<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" href="http://feeds.feedburner.com/bucionrails" type="application/rss+xml" /><feedburner:feedFlare href="http://add.my.yahoo.com/rss?url=http%3A%2F%2Ffeeds.feedburner.com%2Fbucionrails" src="http://us.i1.yimg.com/us.yimg.com/i/us/my/addtomyyahoo4.gif">Subscribe with My Yahoo!</feedburner:feedFlare><feedburner:feedFlare href="http://www.newsgator.com/ngs/subscriber/subext.aspx?url=http%3A%2F%2Ffeeds.feedburner.com%2Fbucionrails" src="http://www.newsgator.com/images/ngsub1.gif">Subscribe with NewsGator</feedburner:feedFlare><feedburner:feedFlare href="http://feeds.my.aol.com/add.jsp?url=http%3A%2F%2Ffeeds.feedburner.com%2Fbucionrails" src="http://o.aolcdn.com/favorites.my.aol.com/webmaster/ffclient/webroot/locale/en-US/images/myAOLButtonSmall.gif">Subscribe with My AOL</feedburner:feedFlare><feedburner:feedFlare href="http://www.bloglines.com/sub/http://feeds.feedburner.com/bucionrails" src="http://www.bloglines.com/images/sub_modern11.gif">Subscribe with Bloglines</feedburner:feedFlare><feedburner:feedFlare href="http://www.netvibes.com/subscribe.php?url=http%3A%2F%2Ffeeds.feedburner.com%2Fbucionrails" src="http://www.netvibes.com/img/add2netvibes.gif">Subscribe with Netvibes</feedburner:feedFlare><feedburner:feedFlare href="http://fusion.google.com/add?feedurl=http%3A%2F%2Ffeeds.feedburner.com%2Fbucionrails" src="http://buttons.googlesyndication.com/fusion/add.gif">Subscribe with Google</feedburner:feedFlare><feedburner:feedFlare href="http://www.pageflakes.com/subscribe.aspx?url=http%3A%2F%2Ffeeds.feedburner.com%2Fbucionrails" src="http://www.pageflakes.com/ImageFile.ashx?instanceId=Static_4&amp;fileName=ATP_blu_91x17.gif">Subscribe with Pageflakes</feedburner:feedFlare><item>
		<title>A prime example of not eating your own dog food</title>
		<link>http://feedproxy.google.com/~r/bucionrails/~3/UPXD02tg17I/</link>
		<comments>http://bucionrails.com/2009/07/14/a-prime-example-of-not-eating-your-own-dog-food/#comments</comments>
		<pubDate>Tue, 14 Jul 2009 16:49:51 +0000</pubDate>
		<dc:creator>balint</dc:creator>
		
		<category><![CDATA[misc]]></category>

		<guid isPermaLink="false">http://bucionrails.com/?p=61</guid>
		<description><![CDATA[I realized how 20th century (plus boring and error-prone) it is to write one&#8217;s invoices by hand. So I went looking for an invoicing application. My expectations were quite low: I wanted one which can be used from my MacBook, has some basic functions that cut down on typing (e.g a client &#8220;database&#8221;), has a [...]]]></description>
			<content:encoded><![CDATA[<p>I realized how 20th century (plus boring and error-prone) it is to write one&#8217;s invoices by hand. So I went looking for an invoicing application. My expectations were quite low: I wanted one which can be used from my MacBook, has some basic functions that cut down on typing (e.g a client &#8220;database&#8221;), has a decent design and UI, can make out invoices in different currencies and did not cost more than ~$100.</p>
<p>It seemed like I have found <a href="http://www.native.hu">one</a>, which, though it had several minor bugs, seemed acceptable, so I purchased the Basic version. Everything went reasonably well until I had to make out my first invoice in euros. It turned out that the Basic version can only make invoices in Hungarian forints in spite of having a couple of other functionalities (e.g set the VAT rate to 0% automatically on invoices made out to EU companies) which made me think it could make it in euros, too.</p>
<p>Ok, so accounting hell got me again. I sighed and asked the <a href="http://www.awasoft.hu/">company</a> how much it would cost to have this funcionality. I was informed I had to buy the upgrade to the Business version which costs ~$120 more, roughly the double of the original price I paid! That was too much to take, so I went looking for another invoicing application. After all, it should not be an insurmountable task to write such an app, I murmured to myself.</p>
<p>I did find a <a href="http://lessaccounting.com">couple of</a> <a href="http://billingsapp.com">very good</a> applications which even overdo what I want them to accomplish. However, the Hungarian homologue of the IRS basically shuts out any foreign competitors by regulating very heavily which conditions must be fulfilled by an invoicing application for a Hungarian company to be able to use it. Bummer.</p>
<p>&#8220;There is still a glimmer of hope.&#8221; - I thought. I checked the Hungarian scene still thinking it could not be that difficult to meet my expectations. Well, apparently I was wrong. The <a href="http://szamlazz.hu">ones</a> <a href="http://cipo.hu">I</a> <a href="https://symbion.eu/">found</a> are either overcomplicated to use, look like home pages in the 80s or are way too expensive. Sometimes all of these. So I put off the challenge of finding an acceptable piece of software and got back of writing invoices manually.</p>
<p>Now you might wonder where <a href="http://en.wikipedia.org/wiki/Eating_one%27s_own_dog_food">the dog food</a> is in the story. Well, today I received the invoice from the company of my purchase of the Basic version of the application. It was written manually on an invoice sheet :) That&#8217;s tantamount of Steve Jobs using a PC with Windows Vista.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/bucionrails?a=UPXD02tg17I:nWsLIS7K5NU:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/bucionrails?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/bucionrails?a=UPXD02tg17I:nWsLIS7K5NU:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/bucionrails?i=UPXD02tg17I:nWsLIS7K5NU:F7zBnMyn0Lo" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/bucionrails/~4/UPXD02tg17I" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://bucionrails.com/2009/07/14/a-prime-example-of-not-eating-your-own-dog-food/feed/</wfw:commentRss>
		<feedburner:origLink>http://bucionrails.com/2009/07/14/a-prime-example-of-not-eating-your-own-dog-food/</feedburner:origLink></item>
		<item>
		<title>John Doe is dull: the importance of choosing good user names in tests</title>
		<link>http://feedproxy.google.com/~r/bucionrails/~3/fcIk4209HCs/</link>
		<comments>http://bucionrails.com/2009/07/12/john-doe-is-dull-the-importance-of-choosing-good-user-names-in-tests/#comments</comments>
		<pubDate>Sun, 12 Jul 2009 07:00:23 +0000</pubDate>
		<dc:creator>balint</dc:creator>
		
		<category><![CDATA[productivity]]></category>

		<guid isPermaLink="false">http://bucionrails.com/?p=59</guid>
		<description><![CDATA[We, developers, have to come up with user names all the time. In this glorious, pioneer era of TDD, more than ever we have to not only enter them into text fields but write them in test files that are part of the code and thus are clearly visible and permanent.
So it is important to [...]]]></description>
			<content:encoded><![CDATA[<p>We, developers, have to come up with user names all the time. In this glorious, pioneer era of TDD, more than ever we have to not only enter them into text fields but write them in test files that are part of the code and thus are clearly visible and permanent.</p>
<p>So it is important to give good names, but what is a good name like? I am not thinking about the semantics of the name (whether it has accented letters, or if it has two or three parts, etc.) but look at them from a very personal point of view: whether it makes you, the programmer, satisfied with your choice of names or bored with repeating the same old names you used in other projects and even in those projects, you had copied them from somewhere.</p>
<p>So when writing your first test where a user is needed, stop for a moment and imagine a world which you like and which is amusing in the context of your application&#8217;s domain (like <a href="http://www.youtube.com/watch?v=F2kAnTZBnTg">philosophers playing soccer</a>, Luddites attending a technology conference, etc.). Pick some names and let the feeling that you have created something instead of just using old, boring names fill you with contentment. Whenever you need an other name, take one from your world. If you need further data (e.g date of birth) about your test users you can even do a little bit of research.</p>
<p>Though investing energy in this may reduce the time you spend writing code, compared to all the hours you put into a project, it is negligible. Nurturing this &#8220;subculture&#8221; in your tests can be very entertaining so you have a good time developing and are less prone to boredom. I think it pays off. We, Ruby programmers all know how important it is to be happy while programming and the effect it has on our productivity.</p>
<p>And besides, do you know of anyone who is called John Doe?</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/bucionrails?a=fcIk4209HCs:sUiO4bF-odc:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/bucionrails?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/bucionrails?a=fcIk4209HCs:sUiO4bF-odc:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/bucionrails?i=fcIk4209HCs:sUiO4bF-odc:F7zBnMyn0Lo" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/bucionrails/~4/fcIk4209HCs" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://bucionrails.com/2009/07/12/john-doe-is-dull-the-importance-of-choosing-good-user-names-in-tests/feed/</wfw:commentRss>
		<feedburner:origLink>http://bucionrails.com/2009/07/12/john-doe-is-dull-the-importance-of-choosing-good-user-names-in-tests/</feedburner:origLink></item>
		<item>
		<title>The hashtag (HRT) retweet bot gemified</title>
		<link>http://feedproxy.google.com/~r/bucionrails/~3/rAEBfWR4ccE/</link>
		<comments>http://bucionrails.com/2009/07/10/the-hashtag-hrt-retweet-bot-gemified/#comments</comments>
		<pubDate>Fri, 10 Jul 2009 16:48:10 +0000</pubDate>
		<dc:creator>balint</dc:creator>
		
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://bucionrails.com/?p=60</guid>
		<description><![CDATA[A very simple twitter bot that retweeted everything that was tagged by a certain tag was put together for Scotland on Rails &#8216;09. Then, Jaime Iniesta adapted it for Euruko &#8216;09. I then forked from his repository, made a few simplifications and minor improvements and DRY-d its configuration.
Maybe most importantly I then turned it into [...]]]></description>
			<content:encoded><![CDATA[<p>A very simple twitter bot that retweeted everything that was tagged by a certain tag was put together for Scotland on Rails &#8216;09. Then, <a href="http://www.jaimeiniesta.com/">Jaime Iniesta</a> adapted it for Euruko &#8216;09. I then forked from his repository, made a few simplifications and minor improvements and DRY-d its configuration.</p>
<p>Maybe most importantly I then turned it into <a href="http://github.com/balinterdi/hashtag_retweet_bot">a gem</a> so that configuration files (including the bot&#8217;s which has the credentials for the twitter account) do not have to be included in the repository.</p>
<p>I also set up <a href="http://twitter.com/budapestrb">a twitter account for the budapest.rb</a> group where an instance of the HRT  bot will post any tweets that have been tagged with #budapestrb. So, my fellow budapest.rb programmers, if you have anything to say about the budapest.rb, just make sure you include the #budapestrb tag in your tweet and watch the HRT bot repeat it.</p>
<p>To launch your own hashtag retweet bot, just follow the instructions in <a href="http://github.com/balinterdi/hashtag_retweet_bot/tree/master">the README</a>.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/bucionrails?a=rAEBfWR4ccE:MExxzO2el70:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/bucionrails?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/bucionrails?a=rAEBfWR4ccE:MExxzO2el70:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/bucionrails?i=rAEBfWR4ccE:MExxzO2el70:F7zBnMyn0Lo" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/bucionrails/~4/rAEBfWR4ccE" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://bucionrails.com/2009/07/10/the-hashtag-hrt-retweet-bot-gemified/feed/</wfw:commentRss>
		<feedburner:origLink>http://bucionrails.com/2009/07/10/the-hashtag-hrt-retweet-bot-gemified/</feedburner:origLink></item>
		<item>
		<title>Pragmatic Thinking and Learning on Twitter</title>
		<link>http://feedproxy.google.com/~r/bucionrails/~3/wX1epjUDez8/</link>
		<comments>http://bucionrails.com/2009/07/03/pragmatic-thinking-and-learning-on-twitter/#comments</comments>
		<pubDate>Fri, 03 Jul 2009 19:20:54 +0000</pubDate>
		<dc:creator>balint</dc:creator>
		
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://bucionrails.com/?p=58</guid>
		<description><![CDATA[Some of you may be aware of my grandiose plans with my twitter mini-framework named twuckoo. For my part I am constantly thinking about -hopefully reasonable- ways that it could be used for the better of mankind :)
The other part of the story is my enthusiasm with Pragmatic Programmers books. I have recently started Pragmatic [...]]]></description>
			<content:encoded><![CDATA[<p>Some of you may be aware of my grandiose plans with my twitter mini-framework named <a href="http://bucionrails.com/2009/06/22/twuckoo/">twuckoo</a>. For my part I am constantly thinking about -hopefully reasonable- ways that it could be used for the better of mankind :)</p>
<p>The other part of the story is my enthusiasm with Pragmatic Programmers books. I have recently started <a href="http://pragprog.com/titles/ahptl/pragmatic-thinking-and-learning">Pragmatic Thinking and Learning</a> by Andy Hunt which is also a very good one and found the familiar &#8220;resuming card&#8221; at the end. This card sums up the wisdom of the book in short phrases just so that you can recall what you read quickly. It is a great idea and can be found in other PP books, too.</p>
<p>So I asked at a PP email address which seemed to be closest to copyright questions whether I have the right to do this. To my surprise, it was the author himself, <a href="http://blog.toolshed.com/">Andy Hunt</a>, who answered me and kindly gave me permission for the book in question. (Once again, thank you, Andy!)</p>
<p>So there you have it, <a href="https://twitter.com/pragthinklearn">a twitter account that will serve you an advice each day</a> just so that you can &#8220;refactor your wetware&#8221; (the subtitle of the book) and hopefully help you be a better craftsman.</p>
<p>And now, my little twuckoo, on to world domination!</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/bucionrails?a=wX1epjUDez8:W0BaQN5-YrI:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/bucionrails?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/bucionrails?a=wX1epjUDez8:W0BaQN5-YrI:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/bucionrails?i=wX1epjUDez8:W0BaQN5-YrI:F7zBnMyn0Lo" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/bucionrails/~4/wX1epjUDez8" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://bucionrails.com/2009/07/03/pragmatic-thinking-and-learning-on-twitter/feed/</wfw:commentRss>
		<feedburner:origLink>http://bucionrails.com/2009/07/03/pragmatic-thinking-and-learning-on-twitter/</feedburner:origLink></item>
		<item>
		<title>installing ruby on a linode slice</title>
		<link>http://feedproxy.google.com/~r/bucionrails/~3/aJNyPTzv2vA/</link>
		<comments>http://bucionrails.com/2009/07/02/installing-ruby-on-a-linode-slice/#comments</comments>
		<pubDate>Thu, 02 Jul 2009 20:35:22 +0000</pubDate>
		<dc:creator>balint</dc:creator>
		
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://bucionrails.com/?p=56</guid>
		<description><![CDATA[To be able to experiment freely and find a store for my twuckoos and other goodies I have recently purchased a Linode 360 slice and had Ubuntu 9.04 installed on it. Next thing was setting up ruby (ruby 1.8.6, to be precise).
When deciding about how to install ruby, in part I wanted to have flexibility [...]]]></description>
			<content:encoded><![CDATA[<p>To be able to experiment freely and find a store for my <a href="http://bucionrails.com/2009/06/22/twuckoo/">twuckoos</a> and other goodies I have recently purchased a Linode 360 slice and had Ubuntu 9.04 installed on it. Next thing was setting up ruby (ruby 1.8.6, to be precise).</p>
<p>When deciding about how to install ruby, in part I wanted to have flexibility but mostly I wanted to feel like I am a professional sysadmin for some hours so I balked at pre-built ruby packages and went with the roll-your-own approach. I&#8217;ll summarize below the process and some pitfalls I encountered so it might help someone.</p>
<h2>Some basic tools</h2>
<p>First, you will need wget (or curl) to download the sources you will need along the way, so:</p>

<div class="wp_syntax"><div class="code"><pre class="bash">$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> apt-get <span style="color: #c20cb9; font-weight: bold;">install</span> <span style="color: #c20cb9; font-weight: bold;">wget</span></pre></div></div>

<p>Also, before you stare dumbly at the screen (like I did) wondering why can&#8217;t the stupid machine run make when the Makefile is clearly there in the directory , don&#8217;t forget to install make:</p>

<div class="wp_syntax"><div class="code"><pre class="bash">$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> apt-get <span style="color: #c20cb9; font-weight: bold;">install</span> <span style="color: #c20cb9; font-weight: bold;">make</span></pre></div></div>

<h2>Updating the package repos</h2>
<p>Plus, since we&#8217;ll be installing packages that are found in the &#8220;universe&#8221; namespace (or whatever it is called) you should uncomment the below two lines in /etc/apt/sources.list :</p>

<div class="wp_syntax"><div class="code"><pre class="bash">deb http:<span style="color: #000000; font-weight: bold;">//</span>us.archive.ubuntu.com<span style="color: #000000; font-weight: bold;">/</span>ubuntu<span style="color: #000000; font-weight: bold;">/</span> jaunty universe
deb-src http:<span style="color: #000000; font-weight: bold;">//</span>us.archive.ubuntu.com<span style="color: #000000; font-weight: bold;">/</span>ubuntu<span style="color: #000000; font-weight: bold;">/</span> jaunty universe</pre></div></div>

<p>&#8230; and then update your package index:</p>

<div class="wp_syntax"><div class="code"><pre class="bash">$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> apt-get update</pre></div></div>

<h2>Installing some packages ruby needs</h2>
<p>Before we download and build ruby, however, it is recommendable to have the zlib and openssl libraries so ruby can already bind to them. This is one of the things that is a lot easier to see with hindsight, but here I am, blogging this to you:</p>

<div class="wp_syntax"><div class="code"><pre class="bash">$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> apt-get <span style="color: #c20cb9; font-weight: bold;">install</span> zlib1g zlib1g-dev zlibc
$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> apt-get <span style="color: #c20cb9; font-weight: bold;">install</span> openssl</pre></div></div>

<p>It turns out from <a href="http://www.ruby-forum.com/topic/71774">this thread</a>, that the zlib bindings are part of ruby since 1.8.6 so you will not need the libzlib-ruby package.</p>
<p>Now, on to ruby itself.</p>
<h2>Ruby &amp; Rubygems</h2>

<div class="wp_syntax"><div class="code"><pre class="bash">$ <span style="color: #c20cb9; font-weight: bold;">wget</span> <span style="color: #c20cb9; font-weight: bold;">ftp</span>:<span style="color: #000000; font-weight: bold;">//</span><span style="color: #c20cb9; font-weight: bold;">ftp</span>.ruby-lang.org<span style="color: #000000; font-weight: bold;">/</span>pub<span style="color: #000000; font-weight: bold;">/</span>ruby<span style="color: #000000; font-weight: bold;">/</span>ruby<span style="color: #000000;">-1.8</span><span style="color: #000000;">.6</span>-p369.<span style="color: #c20cb9; font-weight: bold;">tar</span>.bz2
<span style="color: #7a0874; font-weight: bold;">&#40;</span>untar and <span style="color: #7a0874; font-weight: bold;">cd</span> to new directory<span style="color: #7a0874; font-weight: bold;">&#41;</span>
$ .<span style="color: #000000; font-weight: bold;">/</span>configure
configure: error: no acceptable C compiler found <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #007800;">$PATH</span></pre></div></div>

<p>Piece of cake:</p>

<div class="wp_syntax"><div class="code"><pre class="bash">$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> apt-get <span style="color: #c20cb9; font-weight: bold;">install</span> <span style="color: #c20cb9; font-weight: bold;">gcc</span>
$ .<span style="color: #000000; font-weight: bold;">/</span>configure
configure: error: <span style="color: #000000; font-weight: bold;">in</span> `<span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>balint<span style="color: #000000; font-weight: bold;">/</span>ruby<span style="color: #000000;">-1.8</span><span style="color: #000000;">.6</span>-p369<span style="color: #ff0000;">':
configure: error: C compiler cannot create executables
See `config.log'</span> <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #c20cb9; font-weight: bold;">more</span> details.</pre></div></div>

<p>A bit harder, but I have quickly found the answer <a href="http://ubuntuforums.org/showthread.php?t=17033">here</a>, and then did:</p>

<div class="wp_syntax"><div class="code"><pre class="bash">$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> apt-get <span style="color: #c20cb9; font-weight: bold;">install</span> libc6-dev <span style="color: #c20cb9; font-weight: bold;">g++</span>
$ .<span style="color: #000000; font-weight: bold;">/</span>configure
$ <span style="color: #c20cb9; font-weight: bold;">make</span>
$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">make</span> <span style="color: #c20cb9; font-weight: bold;">install</span>
$ ruby -e <span style="color: #ff0000;">&quot;p 'hello from linode slice'&quot;</span>
<span style="color: #ff0000;">&quot;hello from linode slice&quot;</span></pre></div></div>

<p>Rolling!</p>
<p>However, we all know that a ruby installation without gems is a toothless tiger (lion?) so we&#8217;ll install rubygems last, first downloading the source, and then installing it:</p>

<div class="wp_syntax"><div class="code"><pre class="bash">$ <span style="color: #c20cb9; font-weight: bold;">wget</span> http:<span style="color: #000000; font-weight: bold;">//</span>rubyforge.org<span style="color: #000000; font-weight: bold;">/</span>frs<span style="color: #000000; font-weight: bold;">/</span>download.php<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">57643</span><span style="color: #000000; font-weight: bold;">/</span>rubygems<span style="color: #000000;">-1.3</span><span style="color: #000000;">.4</span>.tgz
<span style="color: #7a0874; font-weight: bold;">&#40;</span>untar and <span style="color: #7a0874; font-weight: bold;">cd</span> to new directory<span style="color: #7a0874; font-weight: bold;">&#41;</span>
$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> ruby setup.rb</pre></div></div>

<p>If you want to use gems stored on github (and you probably do) it is convenient to add the gem github repository to your gem sources:</p>

<div class="wp_syntax"><div class="code"><pre class="bash">$ gem <span style="color: #7a0874; font-weight: bold;">source</span> -a http:<span style="color: #000000; font-weight: bold;">//</span>gems.github.com
$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> gem <span style="color: #c20cb9; font-weight: bold;">install</span> balinterdi-twuckoo</pre></div></div>

<p>Ok, that&#8217;s all. I hope you have found this useful.</p>
<hr /><em>Note:</em></p>
<p>If you receive an error message similar to the following when trying to install a gem:</p>

<div class="wp_syntax"><div class="code"><pre class="bash"><span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span><span style="color: #7a0874; font-weight: bold;">local</span><span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>ruby<span style="color: #000000; font-weight: bold;">/</span>site_ruby<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">1.8</span><span style="color: #000000; font-weight: bold;">/</span>rubygems<span style="color: #000000; font-weight: bold;">/</span>custom_require.rb:<span style="color: #000000;">31</span>:<span style="color: #000000; font-weight: bold;">in</span> `gem_original_require<span style="color: #ff0000;">': no such file to load -- zlib (LoadError)</span></pre></div></div>

<p>Then you need to install the appropriate lib package and recompile ruby. Go to the directory where you unpacked the ruby source to and do:</p>

<div class="wp_syntax"><div class="code"><pre class="bash">$ <span style="color: #c20cb9; font-weight: bold;">make</span> clean
$ <span style="color: #c20cb9; font-weight: bold;">make</span>
$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">make</span> <span style="color: #c20cb9; font-weight: bold;">install</span></pre></div></div>

<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/bucionrails?a=aJNyPTzv2vA:DPvgDRNgcJA:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/bucionrails?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/bucionrails?a=aJNyPTzv2vA:DPvgDRNgcJA:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/bucionrails?i=aJNyPTzv2vA:DPvgDRNgcJA:F7zBnMyn0Lo" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/bucionrails/~4/aJNyPTzv2vA" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://bucionrails.com/2009/07/02/installing-ruby-on-a-linode-slice/feed/</wfw:commentRss>
		<feedburner:origLink>http://bucionrails.com/2009/07/02/installing-ruby-on-a-linode-slice/</feedburner:origLink></item>
		<item>
		<title>twuckoo - my twitter mini framework</title>
		<link>http://feedproxy.google.com/~r/bucionrails/~3/MRhQFEcijXs/</link>
		<comments>http://bucionrails.com/2009/06/22/twuckoo-my-twitter-mini-framework/#comments</comments>
		<pubDate>Mon, 22 Jun 2009 20:01:40 +0000</pubDate>
		<dc:creator>balint</dc:creator>
		
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://bucionrails.com/?p=53</guid>
		<description><![CDATA[I am reading Andy Hunt&#8217;s excellent Pragmatic Thinking and Learning book. There is a section about so called &#8220;oblique strategies&#8221;, short, mysterious phrases that exercise your mind and make you look at problems from another perspective (e.g &#8220;repetition is a form of change&#8221;).
The suggested intake was once a day and there was a free application [...]]]></description>
			<content:encoded><![CDATA[<p>I am reading Andy Hunt&#8217;s excellent Pragmatic Thinking and Learning book. There is a section about so called &#8220;oblique strategies&#8221;, short, mysterious phrases that exercise your mind and make you look at problems from another perspective (e.g &#8220;repetition is a form of change&#8221;).</p>
<p>The suggested intake was once a day and there was a free application that did just this for Apple computers. However, the application was so outdated that I could no longer run it on my laptop. So, I set out to write that application and after a bit of thinking decided to make a twitter account where I (&#8221;I&#8221; meaning a script that I wrote :) ) would post an oblique strategy each day and then just follow that account. This way, I can also spread the knowledge around.</p>
<p>Thus <a title="Twuckoo" href="http://github.com/balinterdi/twuckoo/tree/master">Twuckoo</a> was born. Twuckoo is a simple program (relying on <a href="http://github.com/cjohansen/twibot/tree/master">twibot</a> for communication with twitter) that lets you periodically post a message on a twitter account. It can fetch the messages from a file, from a database, from the web or whereever you want it to retrieve them from. Its very modular in nature so it delegates the task of getting the next message to twitter and storing the posts to the module. here is currently one generic module, the one that fetches them from a file, and one that fetches them from wikipedia&#8217;s main page. I strongly hope that it is very easy for you to write your own module for your own purpose. Twuckoo aims to follow the &#8220;provide-what&#8217;s-needed-and-then-just-get-out-of-the-way&#8221; principle. Go check out <a href="http://github.com/balinterdi/twuckoo/tree/master">the README</a> for further details.</p>
<p>It&#8217;s quite easy to install and run. You can find an example for the file-fetcher module at <a href="http://twitter.com/daily_oblique">http://twitter.com/daily_oblique</a> and <a href="http://twitter.com/wikipedia_tfa">http://twitter.com/wikipedia_tfa</a> grabs &#8220;Today&#8217;s Featured Article&#8221; from wikipedia and posts the title and the link so you can grow a little wiser each day :)</p>
<p>Since it is modular it&#8217;s very extensible. I kept the API very simple so writing modules should be a piece of cake. Each module has to define the following methods:</p>
<ol>
<li><strong>load_tweets</strong> Loads the messages that can be twittered.</li>
<li><strong>next</strong> Gets the next message that will be posted.</li>
<li><strong>store(tweet)</strong> Store the tweet after it had been posted.</li>
</ol>
<p>Once more, I encourage you to scan through <a href="https://github.com/balinterdi/twuckoo/">the README</a>, devise your own module and let me know about it. Any feedback is very welcome!</p>
<p>Note: For my Hungarian-speaking readers, I gave a <a href="http://docs.google.com/Presentation?id=dccxt9fm_3g8nf5fm5">lightning talk about twuckoo</a> at the latest budapest.rb meetup.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/bucionrails?a=MRhQFEcijXs:3LDnIfRNXDI:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/bucionrails?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/bucionrails?a=MRhQFEcijXs:3LDnIfRNXDI:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/bucionrails?i=MRhQFEcijXs:3LDnIfRNXDI:F7zBnMyn0Lo" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/bucionrails/~4/MRhQFEcijXs" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://bucionrails.com/2009/06/22/twuckoo-my-twitter-mini-framework/feed/</wfw:commentRss>
		<feedburner:origLink>http://bucionrails.com/2009/06/22/twuckoo-my-twitter-mini-framework/</feedburner:origLink></item>
		<item>
		<title>acts_as_trivia: would you like to play?</title>
		<link>http://feedproxy.google.com/~r/bucionrails/~3/VkJ95OLDjnI/</link>
		<comments>http://bucionrails.com/2009/05/18/acts_as_trivia-would-you-like-to-play/#comments</comments>
		<pubDate>Mon, 18 May 2009 06:44:36 +0000</pubDate>
		<dc:creator>balint</dc:creator>
		
		<category><![CDATA[rails]]></category>

		<guid isPermaLink="false">http://bucionrails.com/?p=52</guid>
		<description><![CDATA[We all love playing games, from poker to soccer, from hide&#8217;n seek to &#8230; trivia! I am a great fan of this latter and also of Rails apps so it was kind of natural for me to come up with the idea of using all the data in your Rails app to serve as the [...]]]></description>
			<content:encoded><![CDATA[<p>We all love playing games, from poker to soccer, from hide&#8217;n seek to &#8230; trivia! I am a great fan of this latter and also of Rails apps so it was kind of natural for me to come up with the idea of using all the data in your Rails app to serve as the basis of trivia questions.</p>
<p>The ingredients are few and basic. You have a class with an attribute that is comparable and makes sense to compare (the population of states is a good example, the zip code of addresses is a counter-example).</p>
<h3>Installation</h3>
<h4>Install the gem</h4>
<ol>
<li>Install the gem through Rails&#8217;s config.gem</li>
<p>Put this: </p>
<pre code="bash">
    config.gem "balinterdi-acts_as_trivia", :source => "http://gems.github.com",
:lib => "acts_as_trivia"
</pre>
<p></p>
<p>in your environment.rb and then run <em>rake gems:install</em> or <em>rake gems:unpack</em>.</p>
<li>Install it system-wide with the gem command</li>
<pre code="bash">
  gem install acts_as_trivia --source http://gems.github.com
</pre>
</ol>
<h4>Make your app act as a trivia</h4>
<p></p>
<p>You just have to run the provided trivia from the root of your Rails application:</p>
<pre code="bash">
  ./script/generate acts_as_trivia
</pre>
<h4>Create trivia questions easily from the command line</h4>
<p></p>
<pre code="bash">
    ./script.generate acts_as_trivia_record country population name</pre>
</pre>
<p style="margin-top:20px">This trivia question will be about the <i>population</i> of <i>countries</i> and the  <em>name</em> of each will be used by the provided helpers for the sake of displaying something unique of each country.</p>
<h4>Create the pages to answer and assess trivia</h4>
<p></p>
<p>The acts_as_trivia gem only aims to provide a clean interface and the logic, so you will have to create the <em>new</em> controller action of the <em>TriviaAnswersController</em> and the corresponding view: </p>
<pre code="bash">
  /users/:user_id/trivias/:trivia_id/trivia_answers/new
</pre>
<p  style="margin-top:20px">However, you can take a look at these files in the <a href="=http://gist.github.com/raw/107361/f31caad451f0cca699288700aa3d98291a259fd1/gistfile1.rb">rails app generator</a> or just directly copy them.</p>
<h3>Get right in the game</h3>
<p>Instead of going through the above steps, you can use a rails app generator to set up a trivia app quickly: </p>
<pre code="bash">
rails my_shiny_app -m
http://gist.github.com/raw/107361/f31caad451f0cca699288700aa3d98291a259fd1/gistfile1.rb
</pre>
<p style="margin-top:20px">Once you go through the setup steps of the app generator, you have everything you need to have a functioning trivia app, so you can go to: </p>
<pre code="bash">
  /users/1/trivias/1/trivia_answers/new
</pre>
<p style="margin-top:20px">And if you created model instances you can already answer your first trivia question. For a more technical (and more complete) description, please see <a href="http://github.com/balinterdi/acts_as_trivia/tree/master">the README</a>. Also, since this is a beta version, please make sure to report any bugs you might come across.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/bucionrails?a=VkJ95OLDjnI:jiik1o7hDxs:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/bucionrails?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/bucionrails?a=VkJ95OLDjnI:jiik1o7hDxs:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/bucionrails?i=VkJ95OLDjnI:jiik1o7hDxs:F7zBnMyn0Lo" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/bucionrails/~4/VkJ95OLDjnI" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://bucionrails.com/2009/05/18/acts_as_trivia-would-you-like-to-play/feed/</wfw:commentRss>
		<feedburner:origLink>http://bucionrails.com/2009/05/18/acts_as_trivia-would-you-like-to-play/</feedburner:origLink></item>
		<item>
		<title>protecting actions of owner-type associations</title>
		<link>http://feedproxy.google.com/~r/bucionrails/~3/fWlFRTPhfSU/</link>
		<comments>http://bucionrails.com/2009/05/01/protecting-actions-of-owner-type-associations/#comments</comments>
		<pubDate>Fri, 01 May 2009 09:13:46 +0000</pubDate>
		<dc:creator>balint</dc:creator>
		
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://bucionrails.com/?p=50</guid>
		<description><![CDATA[The actions of a web application basically fall into three categories based on their access rights:

Actions with anonymous access
Actions the user has to be logged in to access. (authenticated actions)
Actions the user needs a certain privilege for to access (authorized actions)

At the implementation level, the first category is obvious, since the actions in this category [...]]]></description>
			<content:encoded><![CDATA[<p>The actions of a web application basically fall into three categories based on their access rights:</p>
<ol>
<li>Actions with anonymous access</li>
<li>Actions the user has to be logged in to access. (authenticated actions)</li>
<li>Actions the user needs a certain privilege for to access (authorized actions)</li>
</ol>
<p>At the implementation level, the first category is obvious, since the actions in this category do not have to be protected. So let&#8217;s shift our attention to the second and third category and consider how access protection for these can be achieved in Rails applications.</p>
<p>Both of these are best done with <a href="http://api.rubyonrails.org/classes/ActionController/Filters/ClassMethods.html">before filters</a> since they run before the control is passed to the action&#8217;s code and provide a DRY way to protect several actions.</p>
<h3>Authenticated actions</h3>
<p>Access restriction is quite straightforward once you have a basic library that provides a method to see if a user is logged in (see <a href="http://github.com/technoweenie/restful-authentication/tree/master">restful-authentication</a> for a full-scale solution):</p>
<p><br/></p>
<pre code="ruby">
class ProfilesController < ApplicationController
  before_filter :login_required
  (...)
  def login_required
    redirect_to login_path unless logged_in?
  end
end
</pre>
<p><br/></p>
<h3>Authorized actions</h3>
<p>This can be more tricky since there is a great deal of possibilities of what privilege is needed to access a certain action (e.g only admins can see the full user list, only managers can edit the employees&#8217; records, etc.).</p>
<p>I realized there is one very prevalent type, though, the owner-type access. Only the owner of a blog can modify its data, only the user of a profile can edit its attributes, only the leader of a project can set its deadline, etc. The number of these is endless and I bet there are basically no sites where this does not come up.</p>
<p>Also, the pattern of this access restriction is pretty much the same in all cases. There is the resource to be protected, its owner and the user currently logged in. For access to be granted, the owner of the resource needs to match the current user. So why not extract the pattern to be reused?</p>
<h3>Only owner</h3>
<p>Hence the <a href="http://github.com/balinterdi/only_owner/tree/master">only-owner plugin</a> (I know I suck at naming projects) was born. By default, it will create a before filter in the controller which checks if it is the owner that wants to access the resource. If it is, access is granted. Otherwise, the user is redirected to the login path. Convention over configuration makes a lot of sense so to get up and running you only need to do these two things:</p>
<p>Install the plugin: </p>
<pre code="bash">
./script/plugin install git://github.com/balinterdi/only_owner.git
</pre>
<p><br/></p>
<p>&#8220;Tag&#8221; the controller to be protected:</p>
<pre code="ruby">
  class ProfilesController > ApplicationController
    only_owner
    (...)
  end
</pre>
<p><br/></p>
<p>That assumes that the profile can reach its user through the user association and that there is a find_profile method in scope in the controller. If your association or the finder method is named otherwise, you can pass the appropriate parameters to define them (:owner and :finder, respectively). As a -sensible, I reckon- convention, all methods in the controller except the new, create, index and show ones will be protected by default. Once again, this can be overridden with the usual :only and :except parameters.</p>
<p>I encourage you to scan through the <a href="http://github.com/balinterdi/only_owner/tree/master">README</a> for the options and especially, as always, to give me some feedback.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/bucionrails?a=fWlFRTPhfSU:nfRAaSvgcuY:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/bucionrails?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/bucionrails?a=fWlFRTPhfSU:nfRAaSvgcuY:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/bucionrails?i=fWlFRTPhfSU:nfRAaSvgcuY:F7zBnMyn0Lo" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/bucionrails/~4/fWlFRTPhfSU" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://bucionrails.com/2009/05/01/protecting-actions-of-owner-type-associations/feed/</wfw:commentRss>
		<feedburner:origLink>http://bucionrails.com/2009/05/01/protecting-actions-of-owner-type-associations/</feedburner:origLink></item>
		<item>
		<title>upstream or downstream?</title>
		<link>http://feedproxy.google.com/~r/bucionrails/~3/-tm68dlSpRY/</link>
		<comments>http://bucionrails.com/2009/04/27/upstream-or-downstream/#comments</comments>
		<pubDate>Mon, 27 Apr 2009 08:41:15 +0000</pubDate>
		<dc:creator>balint</dc:creator>
		
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://bucionrails.com/?p=49</guid>
		<description><![CDATA[With the proliferation of middleware applications the mentions of upstream and downstream servers has intensified so I decided to get to the end of this and find out what exactly an upstream server is. I first looked up wikipedia:

In computer networking, upstream server refers to a server that provides service to another server. In other words, upstream server is [...]]]></description>
			<content:encoded><![CDATA[<p>With the proliferation of <a href="http://chneukirchen.org/blog/archive/2007/02/introducing-rack.html">middleware applications</a> the mentions of upstream and downstream servers has intensified so I decided to get to the end of this and find out what exactly an upstream server is. I first looked up <a href="http://en.wikipedia.org/wiki/Upstream_server">wikipedia</a>:</p>
<blockquote><p>
In <a title="Computer networking" href="http://en.wikipedia.org/wiki/Computer_networking">computer networking</a>, <strong>upstream server</strong> refers to a <a title="Server (computing)" href="http://en.wikipedia.org/wiki/Server_(computing)">server</a> that provides service to another server. In other words, upstream server is a server that is located higher in the <a title="Hierarchy" href="http://en.wikipedia.org/wiki/Hierarchy">hierarchy</a> of servers.
</p></blockquote>
<p>Ok, so based on this simplistic definition, a sketch of a request&#8217;s route to the application server and the response back can be illustrated like this:</p>
<p><img src="http://bucionrails.com/wp-content/uploads/2009/04/request-stack.jpg" border="0" /></p>
<p>In this drawing, the middleware is an upstream server to the underlying application since it provides a service to it (be it caching, url mapping, exception handling and <a href="http://github.com/rack/rack-contrib/tree/master">plenty of others</a>).</p>
<p>So now with my definition established, I was looking for examples in the wild that support it. <a href="http://mwrc2009.confreaks.com/13-mar-2009-11-05-in-a-world-of-middleware-who-needs-monolithic-applications-jon-crosby.html">Jon Crosby&#8217;s excellent presentation</a> at the MountainWest Ruby Conference used upstream in this context as far as I remember. Check one.</p>
<p>Browsing the source code of <a href="http://github.com/rtomayko/rack-cache/tree/master">rack-cache</a> -which, by the way, I strongly encourage you to do if you want to understand caching (better) or just like the look of clean Ruby code- I realized Ryan Tomayko&#8217;s definition of upstream coincides with the above one since he uses downstream in the code to refer to the component/application below the rack-cache component. Check two.</p>
<p>I recently set up an nginx web server as a front end server to a mongrel cluster that runs a Rails application. Ok, so in this case, the nginx server must be the upstream server since requests hit there first and then are passed to the mongrels. One must hear the sound of collapse of cards in my head when I saw the following <a href="http://wiki.nginx.org/NginxHttpUpstreamModule">nginx directive</a>:</p>
<pre code="ruby">
upstream production_mongrels {
  server 127.0.0.1:8000;
  server 127.0.0.1:8001;
  server 127.0.0.1:8002;
}
</pre>
<p>Hmm, what? Nginx is above the component it provides a load-balancing service to so by any -ok, by my- definition the directive should say &#8220;downstream&#8221; and not &#8220;upstream&#8221;.</p>
<p>I realize that the request arrow on the diagram moving from top to bottom is a matter of convention and that it probably correlates with the fact that most languages write from the top to the bottom. Nevertheless, as far as I know Nginx is made by a Russian guy and Russians write top to bottom, too, so he should still use &#8220;downstream&#8221; for the directive, now shouldn&#8217;t he? Or did he simply start to sketch up boxes and arrows from bottom to top for the sake of it when designing his web server?</p>
<p>Summing up, I think the above described convention is the common one but since it is not standardized there will always be people and software that uses it the other way around. I am not overly confident though, so please tell me about your definition or just point to examples which support or contradict mine.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/bucionrails?a=-tm68dlSpRY:YcWbnRyXMb8:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/bucionrails?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/bucionrails?a=-tm68dlSpRY:YcWbnRyXMb8:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/bucionrails?i=-tm68dlSpRY:YcWbnRyXMb8:F7zBnMyn0Lo" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/bucionrails/~4/-tm68dlSpRY" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://bucionrails.com/2009/04/27/upstream-or-downstream/feed/</wfw:commentRss>
		<feedburner:origLink>http://bucionrails.com/2009/04/27/upstream-or-downstream/</feedburner:origLink></item>
		<item>
		<title>have your to_param begin with the record’s id</title>
		<link>http://feedproxy.google.com/~r/bucionrails/~3/mXo54dJz3Cg/</link>
		<comments>http://bucionrails.com/2009/04/24/have-your-to_param-begin-with-the-records-id/#comments</comments>
		<pubDate>Fri, 24 Apr 2009 13:30:17 +0000</pubDate>
		<dc:creator>balint</dc:creator>
		
		<category><![CDATA[rails]]></category>

		<guid isPermaLink="false">http://bucionrails.com/?p=48</guid>
		<description><![CDATA[If you overwrite the to_param method in your model class such that it does not begin with its id, you can be in for a nasty surprise. Let&#8217;s say you have a User class and you want URLs to contain the user&#8217;s login instead of its id.

  class User
    def to_param
 [...]]]></description>
			<content:encoded><![CDATA[<p>If you overwrite the to_param method in your model class such that it does not begin with its id, you can be in for a nasty surprise. Let&#8217;s say you have a User class and you want URLs to contain the user&#8217;s login instead of its id.</p>
<pre code="ruby">
  class User
    def to_param
      self.login
    end
    ...
  end
</pre>
<p>And let’s assume you have a user called &#8220;bob&#8221;. One might think the following works:</p>
<pre code="ruby">
  >> bob = User.find(3)
  => #&lt;User id: 3, login: "bob", ...&gt;
  >> User.find(bob.to_param)
  ActiveRecord::RecordNotFound: Couldn't find User with ID=bob
</pre>
<p>But it does not. That&#8217;s a problem since URLs are created by calling the to_param method of the model instances composing the path and a standard, nice way of finding the model instance (user in our example) in a controller action is to fetch the id (now: user_id) from the controller. That will quickly lead to error messages of the above form.</p>
<p>The reason that it does not work is that ActiveRecord&#8217;s find method will look for a numerical id at the beginning of the argument. It extracts this id and discards anything that comes after it. It then looks up that id in the database and returns the instantiated record. No numerical id results in an error message. The solution from here on is straightforward, have your to_param return a string where the id comes first: </p>
<pre code="ruby">
  class User
    def to_param
      "#{self.id}-#{self.login}"
    end
    ...
  end
</pre>
<pre code="ruby">
>> bob = User.find(3)
=> #&lt;User id: 3, login: "bob", ...&gt;
>> User.find(bob.to_param)
=> #&lt;User id: 3, login: "bob", …&gt;
</pre>
<p>As a splendid way to prove my point but a totally useless piece of information is that you can put any non-numeric value after the id, and find will still find the record:</p>
<pre code="ruby">
>> User.find("3-be-aware-of-what-you-overwrite-to-param-with")
=> #&lt;User id: 3, login: "bob", …&gt;
</pre>
<p>So I hope you have found this useful, see you in the next episode :)</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/bucionrails?a=mXo54dJz3Cg:UIWooZSKvOg:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/bucionrails?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/bucionrails?a=mXo54dJz3Cg:UIWooZSKvOg:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/bucionrails?i=mXo54dJz3Cg:UIWooZSKvOg:F7zBnMyn0Lo" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/bucionrails/~4/mXo54dJz3Cg" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://bucionrails.com/2009/04/24/have-your-to_param-begin-with-the-records-id/feed/</wfw:commentRss>
		<feedburner:origLink>http://bucionrails.com/2009/04/24/have-your-to_param-begin-with-the-records-id/</feedburner:origLink></item>
	</channel>
</rss>
