<?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>info.michael-simons.eu &#187; Rails</title>
	<atom:link href="http://info.michael-simons.eu/tag/rails/feed/" rel="self" type="application/rss+xml" />
	<link>http://info.michael-simons.eu</link>
	<description>Just another nerd blog</description>
	<lastBuildDate>Wed, 08 Feb 2012 10:26:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Logging in Rails outside a controller</title>
		<link>http://info.michael-simons.eu/2009/08/25/logging-in-rails-outside-a-controller/</link>
		<comments>http://info.michael-simons.eu/2009/08/25/logging-in-rails-outside-a-controller/#comments</comments>
		<pubDate>Tue, 25 Aug 2009 05:25:43 +0000</pubDate>
		<dc:creator>Michael</dc:creator>
				<category><![CDATA[English posts]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[Code Snippets]]></category>

		<guid isPermaLink="false">http://info.michael-simons.eu/2009/08/25/logging-in-rails-outside-a-controller/</guid>
		<description><![CDATA[You can use RAILS_DEFAULT_LOGGER.log &#34;foobar&#34; # or Rails.logger.log &#34;blah&#34; outside a controller for logging. Share This]]></description>
			<content:encoded><![CDATA[<p>You can use</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">RAILS_DEFAULT_LOGGER.<span style="color:#9900CC;">log</span> <span style="color:#996600;">&quot;foobar&quot;</span>
<span style="color:#008000; font-style:italic;"># or</span>
Rails.<span style="color:#9900CC;">logger</span>.<span style="color:#9900CC;">log</span> <span style="color:#996600;">&quot;blah&quot;</span></pre></div></div>

<p>outside a controller for logging.</p>
<p class="akst_link"><a href="http://info.michael-simons.eu/?p=364&amp;akst_action=share-this"  title="E-mail this, post to del.icio.us, etc." id="akst_link_364" class="akst_share_link " rel="nofollow">Share This</a>
</p>]]></content:encoded>
			<wfw:commentRss>http://info.michael-simons.eu/2009/08/25/logging-in-rails-outside-a-controller/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Phusion Passenger and memcache-client revisited</title>
		<link>http://info.michael-simons.eu/2009/03/23/phusion-passenger-and-memcache-client-revisited/</link>
		<comments>http://info.michael-simons.eu/2009/03/23/phusion-passenger-and-memcache-client-revisited/#comments</comments>
		<pubDate>Mon, 23 Mar 2009 10:35:49 +0000</pubDate>
		<dc:creator>Michael</dc:creator>
				<category><![CDATA[English posts]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[memcached]]></category>
		<category><![CDATA[Tipps]]></category>

		<guid isPermaLink="false">http://info.michael-simons.eu/?p=313</guid>
		<description><![CDATA[The last Passenger update brought some good explanation off the problems regarding Passenger and memcache-client (see here). Smart spawning of Passenger processes creates shared file descriptors. As the connections to memcached are sockets they are shared as well so data on them gets corrupted which is explained very nicely in the Passenger documentation: Example 1: [...]]]></description>
			<content:encoded><![CDATA[<p>The last <a href="http://www.modrails.com/">Passenger</a> update brought some good explanation off the problems regarding Passenger and memcache-client (see <a href="http://info.michael-simons.eu/2009/02/23/phusion-passenger-and-memcached-memcache-client/">here</a>). </p>
<p>Smart spawning of Passenger processes creates shared file descriptors. As the connections to memcached are sockets they are shared as well so data on them gets corrupted which is explained very nicely in the Passenger documentation: <a href="http://www.modrails.com/documentation/Users%20guide.html#_example_1_memcached_connection_sharing_harmful">Example 1: Memcached connection sharing (harmful)</a>.</p>
<p>The solution presented there works like a charm. The <em>reestablish_connection_to_memcached</em> line is actually not more than <em>CACHE.reset</em> where CACHE is the reference to the memcache connection.</p>
<p>After that change, spawning methods smart-lv2 and smart will work in connection with environment.rb configured memcache connections.</p>
<p><ins datetime="2009-03-25T15:15:15+00:00">Edit</ins>: As requested in the comments, a little example:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">memcache_options = <span style="color:#006600; font-weight:bold;">&#123;</span>
  <span style="color:#ff3333; font-weight:bold;">:c_threshold</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">10000</span>,
  <span style="color:#ff3333; font-weight:bold;">:compression</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">true</span>,
  <span style="color:#ff3333; font-weight:bold;">:debug</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">false</span>,
  <span style="color:#ff3333; font-weight:bold;">:namespace</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'some_ns'</span>,
  <span style="color:#ff3333; font-weight:bold;">:readonly</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">false</span>,
  <span style="color:#ff3333; font-weight:bold;">:urlencode</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">false</span>
<span style="color:#006600; font-weight:bold;">&#125;</span>
&nbsp;
CACHE = MemCache.<span style="color:#9900CC;">new</span> memcache_options
CACHE.<span style="color:#9900CC;">servers</span> = <span style="color:#996600;">'127.0.0.1:11211'</span>
<span style="color:#9966CC; font-weight:bold;">begin</span>
   PhusionPassenger.<span style="color:#9900CC;">on_event</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:starting_worker_process</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>forked<span style="color:#006600; font-weight:bold;">|</span>
     <span style="color:#9966CC; font-weight:bold;">if</span> forked
       <span style="color:#008000; font-style:italic;"># We're in smart spawning mode, so...</span>
       <span style="color:#008000; font-style:italic;"># Close duplicated memcached connections - they will open themselves</span>
       CACHE.<span style="color:#9900CC;">reset</span>
     <span style="color:#9966CC; font-weight:bold;">end</span>
   <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#008000; font-style:italic;"># In case you're not running under Passenger (i.e. devmode with mongrel)</span>
<span style="color:#9966CC; font-weight:bold;">rescue</span> <span style="color:#CC00FF; font-weight:bold;">NameError</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> error
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>In this case, CACHE is the global constant that i use to access my memcache-client.</p>
<p>I guess you&#8217;ll need to do the same with the global Rails.cache object, but i&#8217;m not sure. Anyway, the above solution works for me. </p>
<p class="akst_link"><a href="http://info.michael-simons.eu/?p=313&amp;akst_action=share-this"  title="E-mail this, post to del.icio.us, etc." id="akst_link_313" class="akst_share_link " rel="nofollow">Share This</a>
</p>]]></content:encoded>
			<wfw:commentRss>http://info.michael-simons.eu/2009/03/23/phusion-passenger-and-memcache-client-revisited/feed/</wfw:commentRss>
		<slash:comments>33</slash:comments>
		</item>
		<item>
		<title>Phusion Passenger and memcached / memcache-client</title>
		<link>http://info.michael-simons.eu/2009/02/23/phusion-passenger-and-memcached-memcache-client/</link>
		<comments>http://info.michael-simons.eu/2009/02/23/phusion-passenger-and-memcached-memcache-client/#comments</comments>
		<pubDate>Mon, 23 Feb 2009 16:23:46 +0000</pubDate>
		<dc:creator>Michael</dc:creator>
				<category><![CDATA[English posts]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Tipps]]></category>

		<guid isPermaLink="false">http://info.michael-simons.eu/?p=294</guid>
		<description><![CDATA[I recently switch from a mod_proxy / thin setup to Phusion Passenger and my application started to do the funniest things and the production.log was full with errors related to memcached. It seems, that passengers spawn method &#8220;smart&#8221; isn&#8217;t compatible with memcached. Within seconds on a lightly loaded server the cache gets corrupted big time. [...]]]></description>
			<content:encoded><![CDATA[<p>I recently switch from a mod_proxy / thin setup to <a href="http://www.modrails.com/">Phusion Passenger</a> and my application started to do the funniest things and the production.log was full with errors related to memcached.</p>
<p>It seems, that passengers spawn method &#8220;smart&#8221; isn&#8217;t compatible with memcached. Within seconds on a lightly loaded server the cache gets corrupted big time.</p>
<p>I got better results with a newer memcache client (the ruby gem actually), but for that i need to remove the client from the rails vendor lib. Furthermore, under higher load there still where errors.</p>
<p>Only solution is to set the spawn method to conservative like so</p>

<div class="wp_syntax"><div class="code"><pre class="apache" style="font-family:monospace;">RailsSpawnMethod conservative</pre></div></div>

<p>Problem seems to be known in the Phusion and Rails teams.</p>
<p class="akst_link"><a href="http://info.michael-simons.eu/?p=294&amp;akst_action=share-this"  title="E-mail this, post to del.icio.us, etc." id="akst_link_294" class="akst_share_link " rel="nofollow">Share This</a>
</p>]]></content:encoded>
			<wfw:commentRss>http://info.michael-simons.eu/2009/02/23/phusion-passenger-and-memcached-memcache-client/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Comments are evil?</title>
		<link>http://info.michael-simons.eu/2009/02/23/comments-are-evil/</link>
		<comments>http://info.michael-simons.eu/2009/02/23/comments-are-evil/#comments</comments>
		<pubDate>Mon, 23 Feb 2009 15:19:00 +0000</pubDate>
		<dc:creator>Michael</dc:creator>
				<category><![CDATA[English posts]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[Rants]]></category>

		<guid isPermaLink="false">http://info.michael-simons.eu/?p=291</guid>
		<description><![CDATA[What can cause this snippet to fail: &#60;% if !@day.user.is_rateable? # Workaround für Darstellungsfehler mit Tabellen ohne Bodies im Safari %&#62; &#60;!-- blah --&#62; &#60;% end %&#62; This little snippet fell apart today. I don&#8217;t know if it is passenger, a newer ruby version, RubyInline. All i know is that i am so totally pissed [...]]]></description>
			<content:encoded><![CDATA[<p>What can cause this snippet to fail:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#006600; font-weight:bold;">&lt;%</span> <span style="color:#9966CC; font-weight:bold;">if</span> !@day.<span style="color:#9900CC;">user</span>.<span style="color:#9900CC;">is_rateable</span>?  <span style="color:#008000; font-style:italic;"># Workaround für Darstellungsfehler mit Tabellen ohne Bodies im Safari  %&gt;</span>
&lt;!-- blah --&gt;
<span style="color:#006600; font-weight:bold;">&lt;%</span> <span style="color:#9966CC; font-weight:bold;">end</span> <span style="color:#006600; font-weight:bold;">%&gt;</span></pre></div></div>

<p>This little snippet fell apart today. I don&#8217;t know if it is passenger, a newer ruby version, RubyInline. All i know is that i am so totally pissed of this incredible amount of incompatible versions of just 3 modules that i literally feel like puking. What a hell of a day.</p>
<p>By the way, the thing that broke was the one-line comment right after the if.</p>
<p class="akst_link"><a href="http://info.michael-simons.eu/?p=291&amp;akst_action=share-this"  title="E-mail this, post to del.icio.us, etc." id="akst_link_291" class="akst_share_link " rel="nofollow">Share This</a>
</p>]]></content:encoded>
			<wfw:commentRss>http://info.michael-simons.eu/2009/02/23/comments-are-evil/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Localizing dates and time with Rails&#8217; I18n using procs</title>
		<link>http://info.michael-simons.eu/2009/02/12/localizing-dates-and-time-with-rails-i18n-using-procs/</link>
		<comments>http://info.michael-simons.eu/2009/02/12/localizing-dates-and-time-with-rails-i18n-using-procs/#comments</comments>
		<pubDate>Thu, 12 Feb 2009 14:19:29 +0000</pubDate>
		<dc:creator>Michael</dc:creator>
				<category><![CDATA[English posts]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[Code Snippets]]></category>

		<guid isPermaLink="false">http://info.michael-simons.eu/?p=288</guid>
		<description><![CDATA[Ruby on Rails I18n infrastructure did a great job to internationalization in Rails applications. Most things work right out of the box. Daily Fratze is fully internationalized and i wanted to use ordinal day numbers in the English version. Pity, there is no template for strftime that works that way. As i already hat monkey [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://rubyonrails.org/">Ruby on Rails</a> I18n infrastructure did a great job to internationalization in Rails applications. Most things work right out of the box.</p>
<p><a href="http://dailyfratze.de">Daily Fratze</a> is fully internationalized and i wanted to use ordinal day numbers in the English version. Pity, there is no template for strftime that works that way.</p>
<p>As i already hat monkey patched a &#8220;t&#8221; method to all date and time related classes, i came up with the following solution:</p>
<p>Parallel to &#8220;en.yml&#8221; i now have &#8220;en.rb&#8221; in my locales folder which gets loaded in environment.rb via</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">config.<span style="color:#9900CC;">i18n</span>.<span style="color:#9900CC;">load_path</span> <span style="color:#006600; font-weight:bold;">+</span>= <span style="color:#CC00FF; font-weight:bold;">Dir</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">join</span><span style="color:#006600; font-weight:bold;">&#40;</span>RAILS_ROOT, <span style="color:#996600;">'app'</span>, <span style="color:#996600;">'locales'</span>, <span style="color:#996600;">'*.{yml,rb}'</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#93;</span></pre></div></div>

<p>The en.rb files defines some procs as translation values like so:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#006600; font-weight:bold;">&#123;</span>
  :<span style="color:#996600;">'en'</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#123;</span>
    <span style="color:#ff3333; font-weight:bold;">:date</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#123;</span>
      <span style="color:#ff3333; font-weight:bold;">:formats</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#123;</span>
        <span style="color:#ff3333; font-weight:bold;">:dmy_with_long_month</span>              <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#CC0066; font-weight:bold;">lambda</span> <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#006600; font-weight:bold;">|</span>date<span style="color:#006600; font-weight:bold;">|</span> <span style="color:#996600;">&quot;%B #{date.day.ordinalize}, %Y&quot;</span> <span style="color:#006600; font-weight:bold;">&#125;</span>,
      <span style="color:#006600; font-weight:bold;">&#125;</span>
    <span style="color:#006600; font-weight:bold;">&#125;</span>,
    <span style="color:#ff3333; font-weight:bold;">:time</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#123;</span>
      <span style="color:#ff3333; font-weight:bold;">:formats</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#123;</span>
        <span style="color:#ff3333; font-weight:bold;">:dmy_with_long_month</span>                       <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#CC0066; font-weight:bold;">lambda</span> <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#006600; font-weight:bold;">|</span>date<span style="color:#006600; font-weight:bold;">|</span> <span style="color:#996600;">&quot;%B #{date.day.ordinalize}, %Y&quot;</span> <span style="color:#006600; font-weight:bold;">&#125;</span>,        
        <span style="color:#ff3333; font-weight:bold;">:dmy_with_full_day_and_long_month_and_time</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#CC0066; font-weight:bold;">lambda</span> <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#006600; font-weight:bold;">|</span>date<span style="color:#006600; font-weight:bold;">|</span> <span style="color:#996600;">&quot;%A, %B #{date.day.ordinalize}, %Y at %H:%M&quot;</span> <span style="color:#006600; font-weight:bold;">&#125;</span>
      <span style="color:#006600; font-weight:bold;">&#125;</span>
    <span style="color:#006600; font-weight:bold;">&#125;</span>
  <span style="color:#006600; font-weight:bold;">&#125;</span>
<span style="color:#006600; font-weight:bold;">&#125;</span></pre></div></div>

<p>Used with the standard I18n tools you&#8217;ll end up with the string representation of the proc object. Useless <img src='http://info.michael-simons.eu/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>So time for monkeypatching like so:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">module</span> DateTimeSupport
  <span style="color:#9966CC; font-weight:bold;">def</span> t<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC0066; font-weight:bold;">format</span> = <span style="color:#0000FF; font-weight:bold;">nil</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    type = <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">respond_to</span>?<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:sec</span><span style="color:#006600; font-weight:bold;">&#41;</span> ? <span style="color:#996600;">'time'</span> : <span style="color:#996600;">'date'</span>
    formats = I18n.<span style="color:#9900CC;">translate</span><span style="color:#006600; font-weight:bold;">&#40;</span>:<span style="color:#996600;">&quot;#{type}.formats&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#CC0066; font-weight:bold;">format</span> = formats<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#CC0066; font-weight:bold;">format</span>.<span style="color:#9900CC;">to_sym</span><span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#9966CC; font-weight:bold;">if</span> formats <span style="color:#006600; font-weight:bold;">&amp;&amp;</span> formats<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#CC0066; font-weight:bold;">format</span>.<span style="color:#9900CC;">to_sym</span><span style="color:#006600; font-weight:bold;">&#93;</span>
&nbsp;
    I18n.<span style="color:#9900CC;">localize</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF; font-weight:bold;">self</span>, :<span style="color:#CC0066; font-weight:bold;">format</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#CC0066; font-weight:bold;">format</span>.<span style="color:#9900CC;">respond_to</span>?<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:call</span><span style="color:#006600; font-weight:bold;">&#41;</span> ? <span style="color:#CC0066; font-weight:bold;">format</span>.<span style="color:#9900CC;">call</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF; font-weight:bold;">self</span><span style="color:#006600; font-weight:bold;">&#41;</span> : <span style="color:#CC0066; font-weight:bold;">format</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>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">class</span> <span style="color:#CC00FF; font-weight:bold;">Time</span>
  <span style="color:#9966CC; font-weight:bold;">include</span> DateTimeSupport
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">class</span> <span style="color:#CC00FF; font-weight:bold;">Date</span>
  <span style="color:#9966CC; font-weight:bold;">include</span> DateTimeSupport
<span style="color:#9966CC; font-weight:bold;">end</span>       
&nbsp;
<span style="color:#9966CC; font-weight:bold;">class</span> <span style="color:#CC00FF; font-weight:bold;">DateTime</span>
  <span style="color:#9966CC; font-weight:bold;">include</span> DateTimeSupport
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">class</span> <span style="color:#6666ff; font-weight:bold;">ActiveSupport::TimeWithZone</span>
  <span style="color:#9966CC; font-weight:bold;">include</span> DateTimeSupport
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>Code resides in a file in config/initializers and gets loaded automatically. It adds a t method to all date and time related classes. The method tries to look up the translation of format just like I18n/Simple does.</p>
<p>If it is proc, it gets called and then passed to I18n, otherwise it the original parameter is used.</p>
<p>That way the t method can use &#8220;dmy_with_long_month&#8221;, :dmy_with_long_month and any other arbitrary format like &#8220;%B %Y&#8221; that is not defined in any language file.</p>
<p class="akst_link"><a href="http://info.michael-simons.eu/?p=288&amp;akst_action=share-this"  title="E-mail this, post to del.icio.us, etc." id="akst_link_288" class="akst_share_link " rel="nofollow">Share This</a>
</p>]]></content:encoded>
			<wfw:commentRss>http://info.michael-simons.eu/2009/02/12/localizing-dates-and-time-with-rails-i18n-using-procs/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Different day, same shit: MySQL Gem again</title>
		<link>http://info.michael-simons.eu/2008/12/11/different-day-same-shit-mysql-gem-again/</link>
		<comments>http://info.michael-simons.eu/2008/12/11/different-day-same-shit-mysql-gem-again/#comments</comments>
		<pubDate>Thu, 11 Dec 2008 08:25:37 +0000</pubDate>
		<dc:creator>Michael</dc:creator>
				<category><![CDATA[English posts]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://info.michael-simons.eu/?p=247</guid>
		<description><![CDATA[Again, the MySQL ruby gem totally annyoed me trying to install it on a fresh Mac OS X 10.5.5 install and MySQL 5.0.67. This time the following command brought it to life: sudo env ARCHFLAGS=&#34;-arch i386&#34; gem install mysql -- \ --with-mysql-dir=/usr/local/mysql --with-mysql-lib=/usr/local/mysql/lib \ --with-mysql-include=/usr/local/mysql/include Thanks to a bitter software engineer. Share This]]></description>
			<content:encoded><![CDATA[<p>Again, the MySQL ruby gem <a href="http://info.michael-simons.eu/2006/05/05/ruby-on-rails-mit-mac-os-x/">totally</a> <a href="http://info.michael-simons.eu/2007/01/02/ruby-on-rails-native-mysql-bindings-vs-rmagick/">annyoed</a> me trying to install it on a fresh Mac OS X 10.5.5 install and MySQL 5.0.67.</p>
<p>This time the following command brought it to life:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">env</span> <span style="color: #007800;">ARCHFLAGS</span>=<span style="color: #ff0000;">&quot;-arch i386&quot;</span> gem <span style="color: #c20cb9; font-weight: bold;">install</span> mysql <span style="color: #660033;">--</span> \
  <span style="color: #660033;">--with-mysql-dir</span>=<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>mysql <span style="color: #660033;">--with-mysql-lib</span>=<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>mysql<span style="color: #000000; font-weight: bold;">/</span>lib \
  <span style="color: #660033;">--with-mysql-include</span>=<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>mysql<span style="color: #000000; font-weight: bold;">/</span>include</pre></div></div>

<p>Thanks to a <a href="http://wonko.com/post/how-to-install-the-mysqlruby-gem-on-mac-os-x-leopard">bitter software engineer</a>.</p>
<p class="akst_link"><a href="http://info.michael-simons.eu/?p=247&amp;akst_action=share-this"  title="E-mail this, post to del.icio.us, etc." id="akst_link_247" class="akst_share_link " rel="nofollow">Share This</a>
</p>]]></content:encoded>
			<wfw:commentRss>http://info.michael-simons.eu/2008/12/11/different-day-same-shit-mysql-gem-again/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Rails 2.1: send_file :x_sendfile =&gt; true</title>
		<link>http://info.michael-simons.eu/2008/06/05/rails-21-send_file-x_sendfile-true/</link>
		<comments>http://info.michael-simons.eu/2008/06/05/rails-21-send_file-x_sendfile-true/#comments</comments>
		<pubDate>Thu, 05 Jun 2008 06:17:57 +0000</pubDate>
		<dc:creator>Michael</dc:creator>
				<category><![CDATA[English posts]]></category>
		<category><![CDATA[Rails]]></category>

		<guid isPermaLink="false">http://info.michael-simons.eu/?p=174</guid>
		<description><![CDATA[The &#8220;x_sendfile&#8221; argument on the send_file method in Rails 2.1 is not well thought off as it has an impact in development mode also. I guess most Rails coders won&#8217;t have Apache proxying their mongrels in dev mode and so they don&#8217;t get to see any images or files but the plain path information. I&#8217;ll [...]]]></description>
			<content:encoded><![CDATA[<p>The &#8220;x_sendfile&#8221; argument on the send_file method in Rails 2.1 is not well thought off as it has an impact in development mode also. I guess most Rails coders won&#8217;t have Apache proxying their mongrels in dev mode and so they don&#8217;t get to see any images or files but the plain path information.</p>
<p>I&#8217;ll guess i stay with the x_send_file solution as described <a href="http://info.michael-simons.eu/2008/01/23/turning-off-x_send_file-in-development-mode/">here</a>.</p>
<p class="akst_link"><a href="http://info.michael-simons.eu/?p=174&amp;akst_action=share-this"  title="E-mail this, post to del.icio.us, etc." id="akst_link_174" class="akst_share_link " rel="nofollow">Share This</a>
</p>]]></content:encoded>
			<wfw:commentRss>http://info.michael-simons.eu/2008/06/05/rails-21-send_file-x_sendfile-true/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PDF::Writer and Ruby on Rails 2.1</title>
		<link>http://info.michael-simons.eu/2008/06/04/pdfwriter-and-ruby-on-rails-21/</link>
		<comments>http://info.michael-simons.eu/2008/06/04/pdfwriter-and-ruby-on-rails-21/#comments</comments>
		<pubDate>Wed, 04 Jun 2008 06:50:40 +0000</pubDate>
		<dc:creator>Michael</dc:creator>
				<category><![CDATA[English posts]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[Code Snippets]]></category>

		<guid isPermaLink="false">http://info.michael-simons.eu/?p=171</guid>
		<description><![CDATA[Some days ago, Ruby On Rails 2.1 saw the light of day and as usual, i eagerly updated my Daily Fratze project. I had some minor problems due to an old version of will_paginate and some major ones with my use of PDF::Writer. The PDF::Writer library still works very well but the the instructions here [...]]]></description>
			<content:encoded><![CDATA[<p>Some days ago, <a href="http://weblog.rubyonrails.org/2008/6/1/rails-2-1-time-zones-dirty-caching-gem-dependencies-caching-etc">Ruby On Rails 2.1</a> saw the light of day and as usual, i eagerly updated my <a href="http://dailyfratze.de">Daily Fratze project</a>.</p>
<p>I had some minor problems due to an old version of <a href="http://rock.errtheblog.com/will_paginate">will_paginate</a> and some major ones with my use of <a href="http://ruby-pdf.rubyforge.org/pdf-writer/">PDF::Writer</a>.</p>
<p>The PDF::Writer library still works very well but the the instructions <a href="http://wiki.rubyonrails.org/rails/pages/HowtoGeneratePDFs">here</a> (under PDF::Writer (Austin Ziegler) on how the register an &#8220;rpdf&#8221; template handler don&#8217;t apply anymore due to changes in the Rails template system but can easily be fixed:</p>
<p>In <em>environment.rb</em> change</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#6666ff; font-weight:bold;">ActionView::Base</span>.<span style="color:#9900CC;">register_template_handler</span> <span style="color:#996600;">'rpdf'</span>, <span style="color:#6666ff; font-weight:bold;">ActionView::PDFRender</span></pre></div></div>

<p>to</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#6666ff; font-weight:bold;">ActionView::Template</span>.<span style="color:#9900CC;">register_template_handler</span> <span style="color:#996600;">'rpdf'</span>, <span style="color:#6666ff; font-weight:bold;">ActionView::PDFRender</span></pre></div></div>

<p>And also change your ActionView::PDFRender class to:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">module</span> ActionView <span style="color:#008000; font-style:italic;"># :nodoc:</span>
  <span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'pdf/writer'</span>
  <span style="color:#9966CC; font-weight:bold;">class</span> PDFRender
    PAPER = <span style="color:#996600;">'A4'</span>
    <span style="color:#9966CC; font-weight:bold;">include</span> ApplicationHelper
    <span style="color:#9966CC; font-weight:bold;">include</span> <span style="color:#6666ff; font-weight:bold;">ActionView::Helpers::AssetTagHelper</span>
    <span style="color:#9966CC; font-weight:bold;">include</span> <span style="color:#6666ff; font-weight:bold;">ActionView::Helpers::TextHelper</span>      
    <span style="color:#9966CC; font-weight:bold;">include</span> <span style="color:#6666ff; font-weight:bold;">ActionView::Helpers::TagHelper</span>
    <span style="color:#9966CC; font-weight:bold;">include</span> <span style="color:#6666ff; font-weight:bold;">ActionView::Helpers::UrlHelper</span>
&nbsp;
    <span style="color:#9966CC; font-weight:bold;">def</span> initialize<span style="color:#006600; font-weight:bold;">&#40;</span>action_view<span style="color:#006600; font-weight:bold;">&#41;</span>
      <span style="color:#0066ff; font-weight:bold;">@action_view</span> = action_view
    <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
    <span style="color:#008000; font-style:italic;"># Render the PDF</span>
    <span style="color:#9966CC; font-weight:bold;">def</span> render<span style="color:#006600; font-weight:bold;">&#40;</span>template, local_assigns = <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
      <span style="color:#0066ff; font-weight:bold;">@action_view</span>.<span style="color:#9900CC;">controller</span>.<span style="color:#9900CC;">headers</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">&quot;Content-Type&quot;</span><span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#006600; font-weight:bold;">||</span>= <span style="color:#996600;">'application/pdf'</span>
&nbsp;
      <span style="color:#008000; font-style:italic;"># Retrieve controller variables</span>
      <span style="color:#0066ff; font-weight:bold;">@action_view</span>.<span style="color:#9900CC;">controller</span>.<span style="color:#9900CC;">instance_variables</span>.<span style="color:#9900CC;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>v<span style="color:#006600; font-weight:bold;">|</span>
        instance_variable_set<span style="color:#006600; font-weight:bold;">&#40;</span>v, <span style="color:#0066ff; font-weight:bold;">@action_view</span>.<span style="color:#9900CC;">controller</span>.<span style="color:#9900CC;">instance_variable_get</span><span style="color:#006600; font-weight:bold;">&#40;</span>v<span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
      <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
      pdf = ::<span style="color:#6666ff; font-weight:bold;">PDF::Writer</span>.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#ff3333; font-weight:bold;">:paper</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> PAPER <span style="color:#006600; font-weight:bold;">&#41;</span>
      pdf.<span style="color:#9900CC;">compressed</span> = <span style="color:#0000FF; font-weight:bold;">true</span> <span style="color:#9966CC; font-weight:bold;">if</span> RAILS_ENV != <span style="color:#996600;">'development'</span>
      <span style="color:#CC0066; font-weight:bold;">eval</span> template.<span style="color:#9900CC;">source</span>, <span style="color:#0000FF; font-weight:bold;">nil</span>, <span style="color:#996600;">&quot;#{@action_view.base_path}/#{@action_view.first_render}.#{@action_view.finder.pick_template_extension(@action_view.first_render)}&quot;</span> 
&nbsp;
      pdf.<span style="color:#9900CC;">render</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
    <span style="color:#9966CC; font-weight:bold;">def</span> <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">compilable</span>?
      <span style="color:#0000FF; font-weight:bold;">false</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
    <span style="color:#9966CC; font-weight:bold;">def</span> compilable?
      <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9966CC; font-weight:bold;">class</span>.<span style="color:#9900CC;">compilable</span>?
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>And enjoy happy PDF generation <img src='http://info.michael-simons.eu/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p class="akst_link"><a href="http://info.michael-simons.eu/?p=171&amp;akst_action=share-this"  title="E-mail this, post to del.icio.us, etc." id="akst_link_171" class="akst_share_link " rel="nofollow">Share This</a>
</p>]]></content:encoded>
			<wfw:commentRss>http://info.michael-simons.eu/2008/06/04/pdfwriter-and-ruby-on-rails-21/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Turning off x_send_file in development mode</title>
		<link>http://info.michael-simons.eu/2008/01/23/turning-off-x_send_file-in-development-mode/</link>
		<comments>http://info.michael-simons.eu/2008/01/23/turning-off-x_send_file-in-development-mode/#comments</comments>
		<pubDate>Wed, 23 Jan 2008 16:06:35 +0000</pubDate>
		<dc:creator>Michael</dc:creator>
				<category><![CDATA[English posts]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[Code Snippets]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://info.michael-simons.eu/2008/01/23/turning-off-x_send_file-in-development-mode/</guid>
		<description><![CDATA[I just discovered the great x_send_file plugin and technique and use it extensivly for daily fratze. I replaced the majority of send_file calls with x_send_file but not all (the in memory thingies i serve cannot be send through apache). This works great in production mode but in development mode, it fails as there is no [...]]]></description>
			<content:encoded><![CDATA[<p>I just discovered the great <a href="http://john.guen.in/rdoc/x_send_file/">x_send_file</a> plugin and technique and use it extensivly for <a href="http://dailyfratze.de">daily fratze</a>. I replaced the majority of send_file calls with x_send_file but not all (the in memory thingies i serve cannot be send through apache). This works great in production mode but in development mode, it fails as there is no apache sitting in front the mongrels. Therefore i added the following to my $app_home/config/environments/development.rb:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">class</span> <span style="color:#6666ff; font-weight:bold;">ActionController::Base</span>
  <span style="color:#9966CC; font-weight:bold;">def</span> x_send_file<span style="color:#006600; font-weight:bold;">&#40;</span>path, options = <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    send_file<span style="color:#006600; font-weight:bold;">&#40;</span>path, options<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></div></div>

<p>So all calls to x_send_file in dev mode are delegated to the original send_file.</p>
<p>If anyone can present me a cleaner solution, i.e. with method aliasing, feel free to drop a comment.</p>
<p class="akst_link"><a href="http://info.michael-simons.eu/?p=143&amp;akst_action=share-this"  title="E-mail this, post to del.icio.us, etc." id="akst_link_143" class="akst_share_link " rel="nofollow">Share This</a>
</p>]]></content:encoded>
			<wfw:commentRss>http://info.michael-simons.eu/2008/01/23/turning-off-x_send_file-in-development-mode/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Using rubyzip to create zip files on the fly</title>
		<link>http://info.michael-simons.eu/2008/01/21/using-rubyzip-to-create-zip-files-on-the-fly/</link>
		<comments>http://info.michael-simons.eu/2008/01/21/using-rubyzip-to-create-zip-files-on-the-fly/#comments</comments>
		<pubDate>Mon, 21 Jan 2008 09:16:00 +0000</pubDate>
		<dc:creator>Michael</dc:creator>
				<category><![CDATA[English posts]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[Code Snippets]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://info.michael-simons.eu/2008/01/21/using-rubyzip-to-create-zip-files-on-the-fly/</guid>
		<description><![CDATA[In my Daily Fratze project the users should be able to download their faces as a zip file backup. Until now they have been able to upload zip files. For that, i used rubyzip which worked quite well. As a starting point i found a nice article on the joy of rubyzip, but this has [...]]]></description>
			<content:encoded><![CDATA[<p>In my <a href="http://dailyfratze.de">Daily Fratze</a> project the users should be able to download their faces as a zip file backup.</p>
<p>Until now they have been able to upload zip files. For that, i used <a href="http://rubyzip.sourceforge.net/">rubyzip</a> which worked quite well.</p>
<p>As a starting point i found a nice article on the <a href="http://erratic.inkdeep.com/2006/10/17/joy-of-rubyzip/">joy of rubyzip</a>, but this has a major flaw for me. It uses the Zip::ZipFile interface to create its archives. This interfaces takes a filename as parameter and either creates this file if it doesn&#8217;t exists or tries to open it as a zip archive.</p>
<p>I doesn&#8217;t want my directories polluted by some random zip files so i tried to use TempFile. Creating a new TempFile leads to an existing file which Zip::ZipFile cannot open.</p>
<p>My solution uses the more basic interface Zip::ZipOutputStream. Further requirements were adding binary files with arbitrary names and not like in the examples of rubyzip, creating new files with some textual content. Here we go:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'zip/zip'</span>
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'zip/zipfilesystem'</span>
&nbsp;
t = <span style="color:#CC00FF; font-weight:bold;">Tempfile</span>.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;some-weird-temp-file-basename-#{request.remote_ip}&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
<span style="color:#008000; font-style:italic;"># Give the path of the temp file to the zip outputstream, it won't try to open it as an archive.</span>
<span style="color:#6666ff; font-weight:bold;">Zip::ZipOutputStream</span>.<span style="color:#CC0066; font-weight:bold;">open</span><span style="color:#006600; font-weight:bold;">&#40;</span>t.<span style="color:#9900CC;">path</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>zos<span style="color:#006600; font-weight:bold;">|</span>
  some_file_list.<span style="color:#9900CC;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>file<span style="color:#006600; font-weight:bold;">|</span>
    <span style="color:#008000; font-style:italic;"># Create a new entry with some arbitrary name</span>
    zos.<span style="color:#9900CC;">put_next_entry</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;some-funny-name.jpg&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#008000; font-style:italic;"># Add the contents of the file, don't read the stuff linewise if its binary, instead use direct IO</span>
    zos.<span style="color:#CC0066; font-weight:bold;">print</span> <span style="color:#CC00FF; font-weight:bold;">IO</span>.<span style="color:#9900CC;">read</span><span style="color:#006600; font-weight:bold;">&#40;</span>file.<span style="color:#9900CC;">path</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>
<span style="color:#008000; font-style:italic;"># End of the block  automatically closes the file.</span>
<span style="color:#008000; font-style:italic;"># Send it using the right mime type, with a download window and some nice file name.</span>
send_file t.<span style="color:#9900CC;">path</span>, <span style="color:#ff3333; font-weight:bold;">:type</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'application/zip'</span>, <span style="color:#ff3333; font-weight:bold;">:disposition</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'attachment'</span>, <span style="color:#ff3333; font-weight:bold;">:filename</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;some-brilliant-file-name.zip&quot;</span>
<span style="color:#008000; font-style:italic;"># The temp file will be deleted some time...</span>
t.<span style="color:#9900CC;">close</span></pre></div></div>

<p><ins datetime="2008-01-21T12:55:42+00:00"><i>Edit:</i> The basename given to Tempfile.new is what the name says: A basename. It doesn&#8217;t need to denote a full path. Tempfile creates an arbitrary path for you in the default temporary directory.</ins></p>
<p class="akst_link"><a href="http://info.michael-simons.eu/?p=142&amp;akst_action=share-this"  title="E-mail this, post to del.icio.us, etc." id="akst_link_142" class="akst_share_link " rel="nofollow">Share This</a>
</p>]]></content:encoded>
			<wfw:commentRss>http://info.michael-simons.eu/2008/01/21/using-rubyzip-to-create-zip-files-on-the-fly/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic Page Served (once) in 0.553 seconds -->

