<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Article RSS Feed</title>
    <link>http://your-web-site.com/rss/</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description>The main blog feed for my Web site.</description>
    
    
        <item>
          <title>MiniTest, Rails functional tests and Devise</title>
          <description>&lt;h1&gt;MiniTest, Rails functional tests and Devise&lt;/h1&gt;
&lt;p&gt;Here's how I got MiniTest specs running on Rails and Devise, it pieces together various helpers and other bits of info I found with the google.&lt;/p&gt;
&lt;p&gt;&lt;script src=&quot;https://gist.github.com/2990759.js&quot;&gt; &lt;/script&gt;&lt;/p&gt;</description>
          <pubDate>Wed, 04 Jul 2012 04:34:36 GMT</pubDate>
          <guid>http://your-web-site.com/news/2012/07/04/minitest-rails-functional-tests-and-devise/</guid>
          <link>http://your-web-site.com/news/2012/07/04/minitest-rails-functional-tests-and-devise/</link>
        </item>
    
        <item>
          <title>Padrino CMS Template</title>
          <description>&lt;h1&gt;Padrino CMS Template&lt;/h1&gt;
&lt;p&gt;The idea behind this cms template is to give the padrino user a quick and simple way to populate content and build pages, menus, sidebars etc. without losing any of the versatility of Padrino. This is achieved by setting a &lt;a href=&quot;http://www.padrinorb.com/guides/controllers#prioritized-routes&quot; target=&quot;_blank&quot;&gt;low priority route&lt;/a&gt; which maps to '/*path', the path parameter is then used to retrieve content.&lt;/p&gt;
&lt;p&gt;
I intend to package this as a gem when I have a few more items ticked off the TODO list as there are some limitations at the moment (the orm is hardwired as ActiveRecord and rendering as HAML) but as a first draft it's usable. I've generated the base of &lt;a href=&quot;http://cbt.mathewstaplehurst.co.uk&quot; target=&quot;_blank&quot;&gt;Mathew Staplehurst's CBT Website&lt;/a&gt; using it. 
&lt;/p&gt;
&lt;p&gt;
The project is available on Github &lt;a href=&quot;https://github.com/steventux/padrino_cms_template&quot; target=&quot;_blank&quot;&gt;here&lt;/a&gt;. 
Any issues/suggestions are most welcome.
&lt;/p&gt;
&lt;hr/&gt;
&lt;div id=&quot;disqus_thread&quot;&gt;&lt;/div&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
  (function() {
   var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
   dsq.src = 'http://sobyteme.disqus.com/embed.js';
   (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
  })();
&lt;/script&gt;
&lt;noscript&gt;Please enable JavaScript to view the &lt;a href=&quot;http://disqus.com/?ref_noscript=sobyteme&quot;&gt;comments powered by Disqus.&lt;/a&gt;&lt;/noscript&gt;
&lt;a href=&quot;http://disqus.com&quot; class=&quot;dsq-brlink&quot;&gt;blog comments powered by &lt;span class=&quot;logo-disqus&quot;&gt;Disqus&lt;/span&gt;&lt;/a&gt;
</description>
          <pubDate>Tue, 28 Feb 2012 00:00:00 GMT</pubDate>
          <guid>http://your-web-site.com/news/2012/02/28/padrino-cms-template/</guid>
          <link>http://your-web-site.com/news/2012/02/28/padrino-cms-template/</link>
        </item>
    
        <item>
          <title>Hotrod Hayride</title>
          <description>&lt;h3&gt;Wall of Death&lt;/h3&gt;
&lt;iframe width=&quot;560&quot; height=&quot;349&quot; src=&quot;http://www.youtube.com/embed/LskpLapGJTM&quot; frameborder=&quot;0&quot; allowfullscreen&gt;&lt;/iframe&gt;
&lt;p&gt;&lt;a href=&quot;https://picasaweb.google.com/lh/photo/cqbzIGRq166B6-jWV5359A?feat=embedwebsite&quot;&gt;&lt;img src=&quot;https://lh4.googleusercontent.com/-bzfx8N10Q14/Tja7bAF92eI/AAAAAAAAAUg/aYkj5pC1c-c/s600/DSC_0081.jpg&quot; width=&quot;600&quot; /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://picasaweb.google.com/lh/photo/jxNjex9HKzmLEy76zwmbNw?feat=embedwebsite&quot;&gt;&lt;img src=&quot;https://lh4.googleusercontent.com/-29Q1Sko6C8w/Tja7dhUfV2I/AAAAAAAAAUo/5gmf3whvgfo/s600/DSC_0085.jpg&quot; width=&quot;600&quot; /&gt;&lt;/a&gt;&lt;br/&gt;&lt;span&gt;No suspension, no padding, fuel tank frame.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://picasaweb.google.com/lh/photo/zpJp39kV4g0nLe5fX-l3og?feat=embedwebsite&quot;&gt;&lt;img src=&quot;https://lh6.googleusercontent.com/-KnXEurJWB2o/Tja3mV36Z_I/AAAAAAAAAUE/KtEiFNJN274/s600/DSC_0103.jpg&quot; width=&quot;600&quot; /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://picasaweb.google.com/lh/photo/iRw9b8-Zhm6PualUqh6nMA?feat=embedwebsite&quot;&gt;&lt;img src=&quot;https://lh3.googleusercontent.com/-s98Jg1EJmHQ/Tja7S_Sx8SI/AAAAAAAAAUY/kgTFL1kJ1xA/s600/DSC_0126.jpg&quot; width=&quot;600&quot; /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://picasaweb.google.com/lh/photo/IcCrmLIQ7Cf7QKMhEFaCfQ?feat=embedwebsite&quot;&gt;&lt;img src=&quot;https://lh4.googleusercontent.com/-tC0sp_RYuFI/Tja7WHJF0kI/AAAAAAAAAUc/LqnJ-yx2hkY/s600/DSC_0129.jpg&quot; width=&quot;600&quot; /&gt;&lt;/a&gt;&lt;br/&gt;&lt;span&gt;Two Lane Blacktop&lt;/span&gt;&lt;/p&gt;</description>
          <pubDate>Mon, 01 Aug 2011 00:00:00 GMT</pubDate>
          <guid>http://your-web-site.com/news/2011/08/01/hotrod-hayride/</guid>
          <link>http://your-web-site.com/news/2011/08/01/hotrod-hayride/</link>
        </item>
    
        <item>
          <title>Most Rated</title>
          <description>Check out &lt;a href=&quot;http://mostrated.com&quot; target=&quot;_blank&quot;&gt;MostRated.com&lt;/a&gt;</description>
          <pubDate>Thu, 28 Jul 2011 00:00:00 GMT</pubDate>
          <guid>http://your-web-site.com/news/2011/07/28/most-rated/</guid>
          <link>http://your-web-site.com/news/2011/07/28/most-rated/</link>
        </item>
    
        <item>
          <title>ActionView date_select calendar logic in javascript</title>
          <description>&lt;h1&gt;ActionView date_select calendar logic in javascript&lt;/h1&gt;
&lt;p&gt;&lt;a href=&quot;https://gist.github.com/1151384&quot; title=&quot;Here is the gist code snippet&quot;&gt;Here's the Gist&lt;/a&gt;&lt;/p&gt;

&lt;script src=&quot;https://gist.github.com/1151384.js&quot;&gt; &lt;/script&gt;</description>
          <pubDate>Fri, 24 Jun 2011 00:00:00 GMT</pubDate>
          <guid>http://your-web-site.com/news/2011/06/24/actionview-date_select-calendar-logic-in-javascript/</guid>
          <link>http://your-web-site.com/news/2011/06/24/actionview-date_select-calendar-logic-in-javascript/</link>
        </item>
    
        <item>
          <title>Javascript bitwise encoding</title>
          <description>Here's a quick sample of how to do bitwise encoding in javascript:

&lt;script src=&quot;https://gist.github.com/2024426.js&quot;&gt; &lt;/script&gt;</description>
          <pubDate>Fri, 17 Jun 2011 00:00:00 GMT</pubDate>
          <guid>http://your-web-site.com/news/2011/06/17/javascript-bitwise-encoding/</guid>
          <link>http://your-web-site.com/news/2011/06/17/javascript-bitwise-encoding/</link>
        </item>
    
        <item>
          <title>Independent Stove Installations</title>
          <description>&lt;h1&gt;Independent Stove Installations&lt;/h1&gt;
&lt;p&gt;A good friend of mine from Bristol has trained as a &lt;a target=&quot;_blank&quot; href=&quot;http://hetas.co.uk&quot;&gt;HETAS&lt;/a&gt; engineer which means he is able to install wood burning and multi fuel stoves to the required legal standard for UK building regulations.&lt;/p&gt;
&lt;p&gt;With heating costs climbing and bitter winter weather it's a shrewd move training in this field, plus there's &lt;a target=&quot;_blank&quot; href=&quot;http://www.guardian.co.uk/money/2008/mar/08/householdbills.ethicalliving&quot;&gt;nothing like a good fire&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Naturally every business needs a website and that's where I come in, I put together &lt;a target=&quot;_blank&quot; href=&quot;http://independentstoveinstallations.co.uk&quot;&gt;Independent Stove Installations&lt;/a&gt; another Heroku &amp;amp; Radiant website.&lt;/p&gt;
&lt;p&gt;I've used the &lt;a target=&quot;_blank&quot; href=&quot;https://github.com/hairballopolis/radiant-gallery&quot;&gt;Radiant gallery extension&lt;/a&gt;&amp;nbsp;to show the &lt;a target=&quot;_blank&quot; href=&quot;http://independentstoveinstallations.co.uk/recent-installations&quot;&gt;various installations ISI have completed&lt;/a&gt;.&lt;/p&gt;</description>
          <pubDate>Sat, 19 Feb 2011 00:00:00 GMT</pubDate>
          <guid>http://your-web-site.com/news/2011/02/19/independent-stove-installations/</guid>
          <link>http://your-web-site.com/news/2011/02/19/independent-stove-installations/</link>
        </item>
    
        <item>
          <title>RubyProf, Oink and ActiveRecord bloat</title>
          <description>&lt;h3&gt;RubyProf, Oink and ActiveRecord bloat&lt;/h3&gt;
&lt;div class=&quot;posted&quot;&gt;Posted by Steve on December 03, 2010&lt;em&gt;|&lt;/em&gt;&lt;!--img src=&quot;http://spurrd.com/assets/123/comment.png&quot; /--&gt;&lt;a href=&quot;/news/2010/12/03/rubyprof-oink-and-activerecord-bloat/#disqus_thread&quot;&gt;Comments&lt;/a&gt;&lt;/div&gt;
&lt;p&gt;There are some applications that are always gonna hammer the OS, I'm not talking about your common-or-garden web app, think huge amounts of I/O in the shape of huge file uploads, image processing, iso creation, hungry hungry hungry.&lt;/p&gt;
&lt;p&gt;So what to do when you see ruby processes (spawned from passenger) gobbling up 1gb of RAM? The app was already in production so we had to be careful in our approach to profiling and code changes. Time to grab the production db and associated file data and see if the problem could be reproduced locally.&lt;/p&gt;
&lt;p&gt;I'd say this is the hard part of profiling, where to start looking in a fairly large in-production app? A bit f common sense helped here, we knew that there were some expensive processes mainly dealing with large amounts of image processing and large amounts of copying files. My very experienced colleague pointed me at &lt;a target=&quot;_blank&quot; href=&quot;http://www.engineyard.com/blog/2009/thats-not-a-memory-leak-its-bloat/&quot;&gt;this article&lt;/a&gt; detailing common mistakes made when developing with active record.&lt;/p&gt;
&lt;p&gt;So a quick search through the codebase for &lt;span style=&quot;font-family: Courier New;&quot;&gt;all.each&lt;/span&gt; and &lt;span style=&quot;font-family: Courier New;&quot;&gt;find(:all &lt;span style=&quot;font-family: Arial;&quot;&gt;as mentioned in the article lit up some hotspots in the app code where potentially we could be experiencing bloat.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style=&quot;font-family: Courier New;&quot;&gt;&lt;span style=&quot;font-family: Arial;&quot;&gt;Next step was to wrap these code blocks in a ruby profiler block as detailed &lt;a target=&quot;_blank&quot; href=&quot;http://snippets.aktagon.com/snippets/255-How-to-profile-your-Rails-and-Ruby-applications-with-ruby-prof&quot;&gt;here&lt;/a&gt;&lt;/span&gt;&lt;/span&gt; then make the app execute the profiled code block - no changes to the code yet - this is just to get a benchmark.&lt;/p&gt;
&lt;p&gt;Now we made a small but apparently very important change removing a programmatic filter on a large collection (one of those &lt;span style=&quot;font-family: Courier New;&quot;&gt;all.each...&lt;/span&gt; buggers&lt;span style=&quot;font-family: Arial;&quot;&gt;) and swapped in a more precise active record find with conditions and some outer joins to get us the desired collection.&lt;/span&gt; The app was restarted and the same test run again leaving the profiling block in place and bingo processing time was one sixth of the previous run, big improvement in changing 4 lines of code.&lt;/p&gt;
&lt;p&gt;But all this was done in a local production copy, we needed verification of what was causing bloat in production, adding profiling to production was a risk we couldn't take but what we did do was add and configure the &lt;a target=&quot;_blank&quot; href=&quot;https://github.com/noahd1/oink&quot;&gt;oink gem&lt;/a&gt; which gave us a memory stat in the production logs and after a few hours of normal app use the ability to do&lt;span style=&quot;font-family: Courier New;&quot;&gt; $ oink -t 50 log/production.log&lt;/span&gt; which gives the insightful output:&lt;/p&gt;
&lt;p&gt;&lt;span style=&quot;font-family: Courier New;&quot;&gt;---- MEMORY THRESHOLD ----&lt;br /&gt;
THRESHOLD: 50 MB&lt;br /&gt;
&lt;br /&gt;
-- SUMMARY --&lt;br /&gt;
Worst Requests:&lt;br /&gt;
1. Dec 02 11:11:08, 143136 KB, BarController#foo&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;so verification of the bloat as this method was executing the &lt;span style=&quot;font-family: Courier New;&quot;&gt;all.each&lt;/span&gt; mentioned above. All the evidence was converging on this point in code. Marvellous!&lt;/p&gt;
&lt;p&gt;I had never profiled a Rails app before admittedly this was not your average app but the tools used here definitely took us from hunches and presuppositions to good solid evidence and the beginnings of some simple but effective performance refactorings.&lt;/p&gt;
&lt;p&gt;Hope it helps you when your 400lb Gorilla app starts playing up.&lt;/p&gt;
&lt;p&gt;&lt;span style=&quot;font-family: Courier New;&quot;&gt;&lt;span style=&quot;font-family: Arial;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;

&lt;div id=&quot;disqus_thread&quot;&gt;&lt;/div&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
  (function() {
   var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
   dsq.src = 'http://sobyteme.disqus.com/embed.js';
   (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
  })();
&lt;/script&gt;
&lt;noscript&gt;Please enable JavaScript to view the &lt;a href=&quot;http://disqus.com/?ref_noscript=sobyteme&quot;&gt;comments powered by Disqus.&lt;/a&gt;&lt;/noscript&gt;
&lt;a href=&quot;http://disqus.com&quot; class=&quot;dsq-brlink&quot;&gt;blog comments powered by &lt;span class=&quot;logo-disqus&quot;&gt;Disqus&lt;/span&gt;&lt;/a&gt;
</description>
          <pubDate>Fri, 03 Dec 2010 03:26:54 GMT</pubDate>
          <guid>http://your-web-site.com/news/2010/12/03/rubyprof-oink-and-activerecord-bloat/</guid>
          <link>http://your-web-site.com/news/2010/12/03/rubyprof-oink-and-activerecord-bloat/</link>
        </item>
    
        <item>
          <title>Fun fun fun fun fun</title>
          <description>&lt;h3&gt;Fun fun fun fun fun&lt;/h3&gt;
&lt;div class=&quot;posted&quot;&gt;Posted by Steve on November 24, 2010&lt;em&gt;|&lt;/em&gt;&lt;!--img src=&quot;http://spurrd.com/assets/123/comment.png&quot; /--&gt;&lt;a href=&quot;/news/2010/11/24/fun-fun-fun-fun-fun/#disqus_thread&quot;&gt;Comments&lt;/a&gt;&lt;/div&gt;
&lt;p&gt;Say what you like about the tories, they know how to get the kids rioting...&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;http://london.indymedia.org/system/photo/2010/11/24/5157/resize_p241110_14.481000010.jpg&quot;&gt;&lt;img src=&quot;http://london.indymedia.org/system/photo/2010/11/24/5157/resize_p241110_14.481000010-medium.jpg?1290610771&quot; alt=&quot;Resize_p241110_14&quot; /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;http://london.indymedia.org/system/photo/2010/11/24/5158/resize_p241110_14.491000011.jpg&quot;&gt;&lt;img src=&quot;http://london.indymedia.org/system/photo/2010/11/24/5158/resize_p241110_14.491000011-medium.jpg?1290610771&quot; alt=&quot;Resize_p241110_14&quot; /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;http://london.indymedia.org/system/photo/2010/11/24/5159/resize_p241110_14.501000012.jpg&quot;&gt;&lt;img src=&quot;http://london.indymedia.org/system/photo/2010/11/24/5159/resize_p241110_14.501000012-medium.jpg?1290610771&quot; alt=&quot;Resize_p241110_14&quot; /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;div id=&quot;disqus_thread&quot;&gt;&lt;/div&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
  (function() {
   var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
   dsq.src = 'http://sobyteme.disqus.com/embed.js';
   (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
  })();
&lt;/script&gt;
&lt;noscript&gt;Please enable JavaScript to view the &lt;a href=&quot;http://disqus.com/?ref_noscript=sobyteme&quot;&gt;comments powered by Disqus.&lt;/a&gt;&lt;/noscript&gt;
&lt;a href=&quot;http://disqus.com&quot; class=&quot;dsq-brlink&quot;&gt;blog comments powered by &lt;span class=&quot;logo-disqus&quot;&gt;Disqus&lt;/span&gt;&lt;/a&gt;
</description>
          <pubDate>Wed, 24 Nov 2010 07:07:25 GMT</pubDate>
          <guid>http://your-web-site.com/news/2010/11/24/fun-fun-fun-fun-fun/</guid>
          <link>http://your-web-site.com/news/2010/11/24/fun-fun-fun-fun-fun/</link>
        </item>
    
        <item>
          <title>Ruby 1.9 String encoding shitfest</title>
          <description>&lt;p&gt;&amp;nbsp;There are countless posts out there, screams in the darkness by developers claiming that &lt;a target=&quot;_blank&quot; href=&quot;http://groups.google.com/group/padrino/search?group=padrino&amp;amp;q=encoding&amp;amp;qt_g=Search+this+group&quot;&gt;this gem doesn't work with that web framework using Ruby 1.9&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;In my case the problematic layers in the technology stack were Padrino 0.9.14 with Sinatra-1.0 and Typhoeus 0.1.31 plus some other String to byte array conversions in our codebase.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Testing had showed that when the app received input containing umlauts and other accented letters (i.e. multi byte characters) it failed. &lt;a target=&quot;_blank&quot; href=&quot;http://blog.grayproductions.net/articles/ruby_19s_string&quot;&gt;There are some lengthy and detailed explanations and discussions about how Ruby 1.8 handles character encoding differently from Ruby 1.9&lt;/a&gt;. The sort of thing I'd hoped I'd never have to read but some times you just have to get informed. Hopefully this article will help shortcut or reiterate some of this info.&lt;/p&gt;
&lt;p&gt;So lets begin with the rendered view of your web app, a couple of things will help ease the pain here.&lt;/p&gt;
&lt;p&gt;First make sure all your pages contain the correct content-type meta tag:&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;span style=&quot;color: rgb(255, 255, 255); &quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: monospace; white-space: pre; &quot;&gt;&amp;lt;&lt;span class=&quot;start-tag&quot;&gt;meta&lt;/span&gt;&lt;span class=&quot;attribute-name&quot;&gt; http-equiv&lt;/span&gt;=&lt;span class=&quot;attribute-value&quot;&gt;&amp;quot;Content-Type&amp;quot; &lt;/span&gt;&lt;span class=&quot;attribute-name&quot;&gt;content&lt;/span&gt;=&lt;span class=&quot;attribute-value&quot;&gt;&amp;quot;text/html; charset=UTF-8&amp;quot; &lt;/span&gt;&lt;span class=&quot;error&quot;&gt;&lt;span class=&quot;attribute-name&quot;&gt;/&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Secondly make sure that all your forms use the accept-charset attribute in the html form tag or whatever you use to generate the tag:&lt;/p&gt;
&lt;p&gt;&lt;span style=&quot;color: rgb(255, 255, 255); &quot;&gt;&lt;span style=&quot;font-family: 'Courier New'; &quot;&gt;&amp;lt;form accept-charset=&amp;quot;utf-8&amp;quot;...&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;now we know that the pages can display and post multi byte UTF-8 characters, the web application might be a different story...&lt;/p&gt;
&lt;p&gt;One of the next quick fixes to apply which worked well for me was to apply a filter on all requests which forced the encoding of all incoming String params.&lt;/p&gt;
&lt;p&gt;A branch of&amp;nbsp;&lt;a target=&quot;_blank&quot; href=&quot;http://github.com/rkh/sinatra&quot;&gt;RKH's fork of Sinatra&lt;/a&gt;&amp;nbsp;helped with this, there's a utility method in lib/sinatra/base.rb which does the trick...&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;font class=&quot;Apple-style-span&quot; color=&quot;#99CC00&quot; face=&quot;'Courier New'&quot;&gt;
&lt;p&gt;if defined? Encoding&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;if Encoding.default_external.to_s =~ /^ASCII/&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;Encoding.default_external = &amp;quot;UTF-8&amp;quot;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;end&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;Encoding.default_internal ||= Encoding.default_external&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;def force_encoding(data)&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;return if data == self&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;if data.respond_to? :force_encoding&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;data.force_encoding(Encoding.default_external)&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;elsif data.respond_to? :each_value&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;data.each_value { |v| force_encoding(v) }&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;elsif data.respond_to? :each&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;data.each { |v| force_encoding(v) }&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;end&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;end&lt;/p&gt;
&lt;p&gt;else&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;def force_encoding(*) end&lt;/p&gt;
&lt;p&gt;end&lt;/p&gt;
&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;to work with this we need to set some default encodings for our webapp.&lt;/p&gt;
&lt;p&gt;In Padrino this can be done in the &lt;b&gt;app.rb&lt;/b&gt; file:&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;span style=&quot;color: rgb(153, 204, 0); &quot;&gt;&lt;span style=&quot;font-family: 'Courier New'; &quot;&gt;&amp;nbsp;&amp;nbsp;if RUBY_VERSION &amp;lt; '1.9'&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style=&quot;color: rgb(153, 204, 0); &quot;&gt;&lt;span style=&quot;font-family: 'Courier New'; &quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;$KCODE = 'u'&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style=&quot;color: rgb(153, 204, 0); &quot;&gt;&lt;span style=&quot;font-family: 'Courier New'; &quot;&gt;&amp;nbsp;&amp;nbsp;else&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style=&quot;color: rgb(153, 204, 0); &quot;&gt;&lt;span style=&quot;font-family: 'Courier New'; &quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;Encoding.default_external = Encoding::UTF_8&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style=&quot;color: rgb(153, 204, 0); &quot;&gt;&lt;span style=&quot;font-family: 'Courier New'; &quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;Encoding.default_internal = Encoding::UTF_8&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style=&quot;color: rgb(153, 204, 0); &quot;&gt;&lt;span style=&quot;font-family: 'Courier New'; &quot;&gt;&amp;nbsp;&amp;nbsp;end&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;if you are a padrino user who doesn't wanna touch the Sinatra gem you can create a general before filter in &lt;b&gt;app.rb&lt;/b&gt; like this&lt;/p&gt;
&lt;p&gt;&lt;span style=&quot;color: rgb(153, 204, 0); &quot;&gt;&lt;span style=&quot;font-family: 'Courier New'; &quot;&gt;before do&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style=&quot;color: rgb(153, 204, 0); &quot;&gt;&lt;span style=&quot;font-family: 'Courier New'; &quot;&gt;&amp;nbsp;&amp;nbsp;force_encoding(params)&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style=&quot;color: rgb(153, 204, 0); &quot;&gt;&lt;span style=&quot;font-family: 'Courier New'; &quot;&gt;end&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;there are likely other parts of your application stack that will not be UTF-8 friendly, noteably your tests might complain if you attempt to add multi byte characters to your test data.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;Adding the code hint&lt;/p&gt;
&lt;p&gt;&lt;span style=&quot;color: rgb(153, 204, 0); &quot;&gt;&lt;span style=&quot;font-family: 'Courier New'; &quot;&gt;# encoding: utf-8&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;to the first line of the test class files will alleviate this, it's a grubby fix but we live in a world of compromises, what can you do.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;div id=&quot;disqus_thread&quot;&gt;&lt;/div&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
  (function() {
   var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
   dsq.src = 'http://sobyteme.disqus.com/embed.js';
   (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
  })();
&lt;/script&gt;
&lt;noscript&gt;Please enable JavaScript to view the &lt;a href=&quot;http://disqus.com/?ref_noscript=sobyteme&quot;&gt;comments powered by Disqus.&lt;/a&gt;&lt;/noscript&gt;
&lt;a href=&quot;http://disqus.com&quot; class=&quot;dsq-brlink&quot;&gt;blog comments powered by &lt;span class=&quot;logo-disqus&quot;&gt;Disqus&lt;/span&gt;&lt;/a&gt;
&lt;/p&gt;</description>
          <pubDate>Thu, 16 Sep 2010 08:56:32 GMT</pubDate>
          <guid>http://your-web-site.com/news/2010/09/16/ruby-1-9-string-encoding-shitfest/</guid>
          <link>http://your-web-site.com/news/2010/09/16/ruby-1-9-string-encoding-shitfest/</link>
        </item>
    
    
  </channel>
</rss>

