<?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>M. E. Patterson - Author, Geek &#187; thin</title>
	<atom:link href="http://mepatterson.net/tag/thin/feed/" rel="self" type="application/rss+xml" />
	<link>http://mepatterson.net</link>
	<description>bestselling author of Devil&#039;s Hand, a supernatural thriller; writer of fictions and web software</description>
	<lastBuildDate>Sun, 18 Dec 2011 23:19:07 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
	<!-- google_ad_section_end --><!-- google_ad_section_start -->	<item>
		<title>Rails Metal + Thin = no &#8216;each&#8217; for String?</title>
		<link>http://mepatterson.net/2010/01/rails-metal-thin-no-each-for-string/</link>
		<comments>http://mepatterson.net/2010/01/rails-metal-thin-no-each-for-string/#comments</comments>
		<pubDate>Mon, 18 Jan 2010 04:31:17 +0000</pubDate>
		<dc:creator>M. E. Patterson</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[thin]]></category>

		<guid isPermaLink="false">http://digimonkey.com/mepblog/?p=24</guid>
		<description><![CDATA[Just solved an interesting problem when using the latest Thin web server (1.2.5) with Ruby 1.9.1 and Rails Metal. The code in Rails Metal endpoint: &#160; def call&#40;env&#41; &#160; &#160; if env&#91;&#34;PATH_INFO&#34;&#93; =~ /^\/tags.txt/ &#160; &#160; &#160; request = Rack::Request.new&#40;env&#41; &#160; &#160; &#160; params = request.params &#160; &#160; &#160; query = params&#91;'q'&#93; &#160; &#160; &#160; [...]]]></description>
			<content:encoded><![CDATA[<p>Just solved an interesting problem when using the latest Thin web server (1.2.5) with Ruby 1.9.1 and Rails Metal.</p>
<p>The code in Rails Metal endpoint:</p>
<div class="codecolorer-container ruby blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> call<span style="color:#006600; font-weight:bold;">&#40;</span>env<span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">if</span> env<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">&quot;PATH_INFO&quot;</span><span style="color:#006600; font-weight:bold;">&#93;</span> =~ <span style="color:#006600; font-weight:bold;">/</span>^\<span style="color:#006600; font-weight:bold;">/</span>tags.<span style="color:#9900CC;">txt</span><span style="color:#006600; font-weight:bold;">/</span><br />
&nbsp; &nbsp; &nbsp; request = <span style="color:#6666ff; font-weight:bold;">Rack::Request</span>.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span>env<span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; params = request.<span style="color:#9900CC;">params</span><br />
&nbsp; &nbsp; &nbsp; query = params<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'q'</span><span style="color:#006600; font-weight:bold;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">200</span>, <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#996600;">&quot;Content-Type&quot;</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;text/plain&quot;</span> <span style="color:#006600; font-weight:bold;">&#125;</span>, words_from<span style="color:#006600; font-weight:bold;">&#40;</span>query<span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">join</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;<span style="color:#000099;">\n</span>&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#93;</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">else</span><br />
&nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">404</span>, <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#996600;">&quot;Content-Type&quot;</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;text/html&quot;</span> <span style="color:#006600; font-weight:bold;">&#125;</span>, <span style="color:#996600;">&quot;Not Found&quot;</span><span style="color:#006600; font-weight:bold;">&#93;</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span></div></div>
<p>Don&#8217;t worry about what words_from(query) actually does.  It just returns an array of words.  The deal is, I was trying to output a list of tags for use with a javascript autocompleter &#8212; one tag per line in a plain/text file for speed.  Sure, sure, I could use JSON or XML or whatever, but I didn&#8217;t, because it was easier to get the javascript thing working quickly this way and I&#8217;m lazy.</p>
<p>Under ruby 1.8.7 with thin or webrick, this works fine.  Under ruby 1.9.1 with Webrick (ugh!), this works fine.  Under ruby 1.9.1, with Thin, this bombs with:</p>
<blockquote><p>!! Unexpected error while processing request: undefined method `each&#8217; for #&lt;String:0x000001037abd08&gt;</p></blockquote>
<p>After two hours of debugging, here&#8217;s the simple fix &#8212; pass an array with one string element to the return line instead of a pure string object:</p>
<div class="codecolorer-container ruby blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">200</span>, <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#996600;">&quot;Content-Type&quot;</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;text/plain&quot;</span> <span style="color:#006600; font-weight:bold;">&#125;</span>, <span style="color:#006600; font-weight:bold;">&#91;</span>words_from<span style="color:#006600; font-weight:bold;">&#40;</span>query<span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">join</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;<span style="color:#000099;">\n</span>&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#93;</span></div></div>
<p>Seriously?  Yes.  Seriously.</p>
<p>This makes Thin happy and prevents it from trying to enumerate a String, which doesn&#8217;t work in Ruby 1.9.</p>
<p>I haven&#8217;t gone back yet to see if this borks the other web servers, but I&#8217;m using Thin on this one anyway, so at the moment I don&#8217;t really care.  As always, your mileage may vary.</p>
]]></content:encoded>
			<wfw:commentRss>http://mepatterson.net/2010/01/rails-metal-thin-no-each-for-string/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	<!-- google_ad_section_end --></channel>
</rss>

