<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Muziboo Development Blog &#187; ruby on rails</title>
	<atom:link href="http://devblog.muziboo.com/category/ruby-on-rails/feed/" rel="self" type="application/rss+xml" />
	<link>http://devblog.muziboo.com</link>
	<description>Muziboo development stories. Mostly set in ruby land</description>
	<lastBuildDate>Fri, 01 Apr 2011 04:52:32 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Query Reviewer &amp; Log4r</title>
		<link>http://devblog.muziboo.com/2009/09/08/query-reviewer-log4r/</link>
		<comments>http://devblog.muziboo.com/2009/09/08/query-reviewer-log4r/#comments</comments>
		<pubDate>Tue, 08 Sep 2009 10:18:02 +0000</pubDate>
		<dc:creator>prateek</dc:creator>
				<category><![CDATA[ruby on rails]]></category>
		<category><![CDATA[log4r]]></category>
		<category><![CDATA[query_reviewer]]></category>

		<guid isPermaLink="false">http://devblog.muziboo.com/?p=64</guid>
		<description><![CDATA[
			
				
			
		
I recently found a very neat plugin called Query Reviewer for visualizing slow sql queries in your rails app. When I installed it, I saw this error message
NoMethodError: undefined method `silence&#8216; for #&#60;Log4r::Logger:0&#215;39593f8&#62;
You will see this error if you are using log4r for logging instead of the default rails logger. This ticket also talks of [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fdevblog.muziboo.com%2F2009%2F09%2F08%2Fquery-reviewer-log4r%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fdevblog.muziboo.com%2F2009%2F09%2F08%2Fquery-reviewer-log4r%2F&amp;source=muziboo&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>I recently found a very neat plugin called <a href="http://github.com/dsboulder/query_reviewer/tree/master" onclick="javascript:pageTracker._trackPageview('/outbound/article/github.com');">Query Reviewer</a> for visualizing slow sql queries in your rails app. When I installed it, I saw this error message</p>
<p>No<span class="searchword1">Method</span>Error: <span class="searchword0">undefined</span> <span class="searchword1">method</span> <span class="searchword2">`silence</span>&#8216; <span class="searchword3">for</span> #&lt;<span class="searchword4">Log4r</span>::Logger:0&#215;39593f8&gt;</p>
<p>You will see this error if you are using log4r for logging instead of the default rails logger. <a href="http://dev.rubyonrails.org/ticket/2618" onclick="javascript:pageTracker._trackPageview('/outbound/article/dev.rubyonrails.org');">This</a> ticket also talks of the same error in a different scenario. To fix the issue, edit the file <em>vendor/plugins/query_reviewer/lib/query_reviewer/mysql_adapter_extensions.rb</em> and replace all instance of <em>@logger.silence</em> with <em>ActiveRecord::Base.silence</em>.</p>
]]></content:encoded>
			<wfw:commentRss>http://devblog.muziboo.com/2009/09/08/query-reviewer-log4r/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Rails 2.3 routing gotcha with :format</title>
		<link>http://devblog.muziboo.com/2009/05/06/rails-23-routing-gotcha-with-format/</link>
		<comments>http://devblog.muziboo.com/2009/05/06/rails-23-routing-gotcha-with-format/#comments</comments>
		<pubDate>Wed, 06 May 2009 14:43:50 +0000</pubDate>
		<dc:creator>prateek</dc:creator>
				<category><![CDATA[routing]]></category>
		<category><![CDATA[ruby on rails]]></category>

		<guid isPermaLink="false">http://devblog.muziboo.com/2009/05/06/rails-23-routing-gotcha-with-format/</guid>
		<description><![CDATA[
			
				
			
		
I recently upgraded Muziboo to Rails 2.3 and found out that some of my routes were broken. On digging deeper I found out that I had some routes with two version, one without :format and one with :format going to different controllers/actions. I had the route with :format before the route without :format in the [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fdevblog.muziboo.com%2F2009%2F05%2F06%2Frails-23-routing-gotcha-with-format%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fdevblog.muziboo.com%2F2009%2F05%2F06%2Frails-23-routing-gotcha-with-format%2F&amp;source=muziboo&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>I recently upgraded <a href="http://www.muziboo.com" >Muziboo</a> to Rails 2.3 and found out that some of my routes were broken. On digging deeper I found out that I had some routes with two version, one without :format and one with :format going to different controllers/actions. I had the route with :format before the route without :format in the routes.rb file and changing the order fixed the problem. I am not sure why this happened but its been working fine since the change. If you run into routing issues, do try this and let me know if it worked for you. </p>
<div class="zemanta-pixie"><img class="zemanta-pixie-img" src="http://img.zemanta.com/pixy.gif?x-id=70d1c8a6-f261-838d-a447-ae81bec0ab3d" /></div>
]]></content:encoded>
			<wfw:commentRss>http://devblog.muziboo.com/2009/05/06/rails-23-routing-gotcha-with-format/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ferret to Sphinx: Part 1 &#8211; Why and how to integrate it with acts_as_taggable</title>
		<link>http://devblog.muziboo.com/2009/03/21/ferret-to-sphinx-part-1-why-and-how-to-integrate-it-with-acts_as_taggable/</link>
		<comments>http://devblog.muziboo.com/2009/03/21/ferret-to-sphinx-part-1-why-and-how-to-integrate-it-with-acts_as_taggable/#comments</comments>
		<pubDate>Sat, 21 Mar 2009 09:11:21 +0000</pubDate>
		<dc:creator>prateek</dc:creator>
				<category><![CDATA[acts_as_taggable]]></category>
		<category><![CDATA[ruby on rails]]></category>
		<category><![CDATA[sphinx]]></category>
		<category><![CDATA[thinking sphinx]]></category>

		<guid isPermaLink="false">http://devblog.muziboo.com/2009/03/21/ferret-to-sphinx-part-1-why-and-how-to-integrate-it-with-acts_as_taggable/</guid>
		<description><![CDATA[
			
				
			
		
I am currently working on moving Muziboo&#8217;s search from ferret to sphinx. We were using acts_as_ferret (AAF) plugin which provides a very simple rails integration with ferret. AAF binds itself to the active record callbacks and makes index updation painless. However AAF is pretty unstable in production mode and we realized this only lately with [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fdevblog.muziboo.com%2F2009%2F03%2F21%2Fferret-to-sphinx-part-1-why-and-how-to-integrate-it-with-acts_as_taggable%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fdevblog.muziboo.com%2F2009%2F03%2F21%2Fferret-to-sphinx-part-1-why-and-how-to-integrate-it-with-acts_as_taggable%2F&amp;source=muziboo&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>I am currently working on moving <a href="http://www.muziboo.com" >Muziboo&#8217;s</a> search from <a href="http://ferret.davebalmain.com/" onclick="javascript:pageTracker._trackPageview('/outbound/article/ferret.davebalmain.com');">ferret</a> to <a href="http://www.sphinxsearch.com/" onclick="javascript:pageTracker._trackPageview('/outbound/article/www.sphinxsearch.com');">sphinx</a>. We were using <a href="http://rm.jkraemer.net/projects/show/aaf" onclick="javascript:pageTracker._trackPageview('/outbound/article/rm.jkraemer.net');">acts_as_ferret</a> (AAF) plugin which provides a very simple rails integration with ferret. AAF binds itself to the active record callbacks and makes index updation painless. However AAF is pretty unstable in production mode and we realized this only lately with increasing traffic. We often had corrupted indexes and page errors as a result of that (since ferret is almost deeply integrated into models, it breaks a lot of functionality apart from search when something goes wrong). Also another problem with ferret is the high memory usage and the fact that with multiple mongrels, you will have to run a drb process to make sure the index is not written by multiple processes and corrupted.</p>
<p>On looking for alternatives, I found out about <a href="http://ts.freelancing-gods.com/" onclick="javascript:pageTracker._trackPageview('/outbound/article/ts.freelancing-gods.com');">Thinking Sphinx</a>, a plugin that makes it easy to use sphinx in your rails project. There is some <a href="http://ts.freelancing-gods.com/quickstart.html" onclick="javascript:pageTracker._trackPageview('/outbound/article/ts.freelancing-gods.com');">documentation</a> to get you started with TS once you decide to use it and also a <a href="http://peepcode.com/products/thinking-sphinx-pdf" onclick="javascript:pageTracker._trackPageview('/outbound/article/peepcode.com');">peepcode pdf</a> which has some good info. I could get the basic search functionality up and running in no time but had to spend sometime getting some integration going with other plugins. I will detail some of those things in this and next few posts.</p>
<p><a href="http://agilewebdevelopment.com/plugins/acts_as_taggable" onclick="javascript:pageTracker._trackPageview('/outbound/article/agilewebdevelopment.com');">Acts as taggable</a> helps you in tagging your objects and we wanted sphinx to search on the tags too. It turns out that its very simple. All you have to say in your define_index block is</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;">indexes taggings.<span style="color:#9900CC;">tag</span>.<span style="color:#9900CC;">name</span>,  <span style="color:#ff3333; font-weight:bold;">:as</span><span style="color:#006600; font-weight:bold;">=&gt;</span>tag_name</pre></td></tr></table></div>

<p>Just make sure that you restart sphinx and reindex your data before after adding this in your model(s).</p>
<div class="zemanta-pixie"><img class="zemanta-pixie-img" src="http://img.zemanta.com/pixy.gif?x-id=ad9f60a9-8664-4a2b-b54f-bb8b0a8e123e" alt="" /></div>
]]></content:encoded>
			<wfw:commentRss>http://devblog.muziboo.com/2009/03/21/ferret-to-sphinx-part-1-why-and-how-to-integrate-it-with-acts_as_taggable/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Attachment_fu sanitize filename, Regex and Unicode gotcha</title>
		<link>http://devblog.muziboo.com/2008/06/17/attachment-fu-sanitize-filename-regex-and-unicode-gotcha/</link>
		<comments>http://devblog.muziboo.com/2008/06/17/attachment-fu-sanitize-filename-regex-and-unicode-gotcha/#comments</comments>
		<pubDate>Tue, 17 Jun 2008 09:19:17 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[attachment_fu]]></category>
		<category><![CDATA[gotcha]]></category>
		<category><![CDATA[ruby on rails]]></category>
		<category><![CDATA[sanitize filename]]></category>
		<category><![CDATA[unicode]]></category>

		<guid isPermaLink="false">http://prateekdayal.net/tech/?p=14</guid>
		<description><![CDATA[
			
				
			
		
Attachment_fu sanitizes the filenames on uploads to remove any funky character (not 0-9 a-z A-Z, underscore or a period). This is accomplished by the sanitize_filename private method in attachment_fu.rb file

1
2
3
4
5
6
7
8
9
10
def sanitize_filename&#40;filename&#41;
  returning filename.strip do &#124;name&#124;
    # NOTE: File.basename doesn't work right with Windows paths on Unix
    # get [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fdevblog.muziboo.com%2F2008%2F06%2F17%2Fattachment-fu-sanitize-filename-regex-and-unicode-gotcha%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fdevblog.muziboo.com%2F2008%2F06%2F17%2Fattachment-fu-sanitize-filename-regex-and-unicode-gotcha%2F&amp;source=muziboo&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>Attachment_fu sanitizes the filenames on uploads to remove any funky character (not 0-9 a-z A-Z, underscore or a period). This is accomplished by the <em>sanitize_filename</em> private method in <em>attachment_fu.rb</em> file</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">def</span> sanitize_filename<span style="color:#006600; font-weight:bold;">&#40;</span>filename<span style="color:#006600; font-weight:bold;">&#41;</span>
  returning filename.<span style="color:#9900CC;">strip</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>name<span style="color:#006600; font-weight:bold;">|</span>
    <span style="color:#008000; font-style:italic;"># NOTE: File.basename doesn't work right with Windows paths on Unix</span>
    <span style="color:#008000; font-style:italic;"># get only the filename, not the whole path</span>
    name.<span style="color:#CC0066; font-weight:bold;">gsub!</span> <span style="color:#006600; font-weight:bold;">/</span>^.<span style="color:#006600; font-weight:bold;">*</span><span style="color:#006600; font-weight:bold;">&#40;</span>\\<span style="color:#006600; font-weight:bold;">|</span>\<span style="color:#006600; font-weight:bold;">/</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">/</span>, <span style="color:#996600;">''</span>
&nbsp;
    <span style="color:#008000; font-style:italic;"># Finally, replace all non alphanumeric, underscore or periods with underscore</span>
    name.<span style="color:#CC0066; font-weight:bold;">gsub!</span> <span style="color:#006600; font-weight:bold;">/</span><span style="color:#006600; font-weight:bold;">&#91;</span>^\w\.\<span style="color:#006600; font-weight:bold;">-</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">/</span>, <span style="color:#996600;">'_'</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></td></tr></table></div>

<p>The shortcut \w is described <a href="http://www.ruby-doc.org/docs/UsersGuide/rg/regexp.html" onclick="javascript:pageTracker._trackPageview('/outbound/article/www.ruby-doc.org');">here</a> as letter or digit; same as [0-9A-Za-z]. However since ruby regex engine has support for unicode, letter means any unicode character. So it will let characters like 爱与希望 remain. This can be a problem if you are passing a filename containing such characters to a flash player. The flash player just won&#8217;t play the file!</p>
<p>A quick solution would be to check specifically for 0-9A-Za-z. This can be done by changing the function to</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">def</span> sanitize_filename<span style="color:#006600; font-weight:bold;">&#40;</span>filename<span style="color:#006600; font-weight:bold;">&#41;</span>
  returning filename.<span style="color:#9900CC;">strip</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>name<span style="color:#006600; font-weight:bold;">|</span>
   <span style="color:#008000; font-style:italic;"># NOTE: File.basename doesn't work right with Windows paths on Unix</span>
   <span style="color:#008000; font-style:italic;"># get only the filename, not the whole path</span>
   name.<span style="color:#CC0066; font-weight:bold;">gsub!</span> <span style="color:#006600; font-weight:bold;">/</span>^.<span style="color:#006600; font-weight:bold;">*</span><span style="color:#006600; font-weight:bold;">&#40;</span>\\<span style="color:#006600; font-weight:bold;">|</span>\<span style="color:#006600; font-weight:bold;">/</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">/</span>, <span style="color:#996600;">''</span>
&nbsp;
   <span style="color:#008000; font-style:italic;"># Finally, replace all non alphanumeric, underscore or periods with underscore</span>
   <span style="color:#008000; font-style:italic;">#            name.gsub! /[^\w\.\-]/, '_'</span>
   <span style="color:#008000; font-style:italic;">#            Basically strip out the non-ascii alphabets too and replace with x. You don't want all _ :)</span>
    name.<span style="color:#CC0066; font-weight:bold;">gsub!</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">/</span><span style="color:#006600; font-weight:bold;">&#91;</span>^<span style="color:#006666;">0</span><span style="color:#006600; font-weight:bold;">-</span>9A<span style="color:#006600; font-weight:bold;">-</span>Za<span style="color:#006600; font-weight:bold;">-</span>z.\<span style="color:#006600; font-weight:bold;">-</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">/</span>, <span style="color:#996600;">'x'</span><span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></td></tr></table></div>

<p>Finally this is not a problem if non ascii characters don&#8217;t cause any issue in your site.</p>
]]></content:encoded>
			<wfw:commentRss>http://devblog.muziboo.com/2008/06/17/attachment-fu-sanitize-filename-regex-and-unicode-gotcha/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Gateway timeout with haproxy on long requests</title>
		<link>http://devblog.muziboo.com/2008/06/14/gateway-timeout-with-haproxy-on-long-requests/</link>
		<comments>http://devblog.muziboo.com/2008/06/14/gateway-timeout-with-haproxy-on-long-requests/#comments</comments>
		<pubDate>Sat, 14 Jun 2008 06:45:16 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[paypal]]></category>
		<category><![CDATA[ruby on rails]]></category>
		<category><![CDATA[rubyworks]]></category>
		<category><![CDATA[gateway timeout]]></category>
		<category><![CDATA[haproxy]]></category>
		<category><![CDATA[paypal soap api]]></category>

		<guid isPermaLink="false">http://prateekdayal.net/tech/?p=13</guid>
		<description><![CDATA[
			
				
			
		
I was trying to make a payment using PayPal SOAP API today and on a standard rubyworks installation (Apache &#8211;&#62; HAProxy &#8211;&#62; Mongrels), I was getting a Gateway Timeout Error. On checking the logs, I found out that the payment was in fact going through and rails was generating the thanks page too. My first [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fdevblog.muziboo.com%2F2008%2F06%2F14%2Fgateway-timeout-with-haproxy-on-long-requests%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fdevblog.muziboo.com%2F2008%2F06%2F14%2Fgateway-timeout-with-haproxy-on-long-requests%2F&amp;source=muziboo&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>I was trying to make a payment using <a href="http://www.paypaldeveloper.com/pdn/board?board.id=api" onclick="javascript:pageTracker._trackPageview('/outbound/article/www.paypaldeveloper.com');">PayPal SOAP API</a> today and on a standard <a href="http://rubyworks.rubyforge.org/" onclick="javascript:pageTracker._trackPageview('/outbound/article/rubyworks.rubyforge.org');">rubyworks</a> installation (Apache &#8211;&gt; HAProxy &#8211;&gt; Mongrels), I was getting a Gateway Timeout Error. On checking the logs, I found out that the payment was in fact going through and rails was generating the thanks page too. My first doubt was that mod_proxy was timing out while waiting for a response. I tried to increase ProxyTimeout to 120 secs but it had not effect. I then tried to send the request directly to port 3001 (haproxy port in rubyworks) and I still saw the timeout happening. On sending the request to a mongrel directly (I tried on port 3002), the payment went smoothly and the thanks page was rendered. I tried to browse around and found <a href="http://rubyworks.rubyforge.org/manual/haproxy.html" onclick="javascript:pageTracker._trackPageview('/outbound/article/rubyworks.rubyforge.org');">this</a> page where they mention that by default, if mongrel does not respond back in 30 secs, haproxy times it out.</p>
<p>The setting can be increased by simply changing the variable <code>srvtimeout </code>to a larger number (say 120000 for 120 secs) in the configuration file <code>/etc/rails/haproxy.conf</code></p>
]]></content:encoded>
			<wfw:commentRss>http://devblog.muziboo.com/2008/06/14/gateway-timeout-with-haproxy-on-long-requests/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

