<?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>kueda.net &#187; rails</title>
	<atom:link href="http://kueda.net/blog/tag/rails/feed/" rel="self" type="application/rss+xml" />
	<link>http://kueda.net</link>
	<description>I'm Back</description>
	<lastBuildDate>Thu, 02 Feb 2012 19:42:04 +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>Moving a Rails app to Ruby Enterprise Edition</title>
		<link>http://kueda.net/blog/2009/08/28/moving-a-rails-app-to-ruby-enterprise-edition/</link>
		<comments>http://kueda.net/blog/2009/08/28/moving-a-rails-app-to-ruby-enterprise-edition/#comments</comments>
		<pubDate>Fri, 28 Aug 2009 20:03:25 +0000</pubDate>
		<dc:creator>Ken-ichi</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[slicehost]]></category>
		<category><![CDATA[sysadmin]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://kueda.net/?p=286</guid>
		<description><![CDATA[I just put iNaturalist.org on Ruby Enterprise Edition. Unfortunately, I&#8217;m really not seeing any savings in memory consumption, aside from the Passenger ApplicationSpawner taking up a few less MB. Kind of dissapointed. However, installing REE on my Mac was slightly less trivial than I was led to believe. Suffice it to say the REE installer [...]]]></description>
			<content:encoded><![CDATA[<p>I just put <a href="http://inaturalist.org">iNaturalist.org</a> on <a href="http://www.rubyenterpriseedition.com/">Ruby Enterprise Edition</a>.  Unfortunately, I&#8217;m really not seeing any savings in memory consumption, aside from the Passenger ApplicationSpawner taking up a few less MB.  Kind of dissapointed.</p>
<p>However, installing REE on my Mac was slightly less trivial than I was led to believe.  Suffice it to say the REE installer assumes you have dependent libs in <code>/usr</code> or <code>/usr/local</code>, and if you don&#8217;t, there aren&#8217;t any flags you can pass in to change that.  However, you can set ENV vars, so I was able to get the installer to work like this:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">CC</span>=<span style="color: #c20cb9; font-weight: bold;">gcc</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">CXX</span>=<span style="color: #c20cb9; font-weight: bold;">g++</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> .<span style="color: #000000; font-weight: bold;">/</span>installer</pre></div></div>

<p>Basically, the REE installer checks deps by using Ruby to write and compile a C file, but it&#8217;s default path to gcc was not the same as the gcc I normally use.</p>
<p>After that, I had to make sure all my gems were in place.  I ended up installing rails, Hpricot, and ruby-debug (the latter 2 require compiled C) using REE&#8217;s own copy of rubygems, and I made sure the rest of our gems were vendorized.  REE&#8217;s rubygems is just like normal:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">/</span>path<span style="color: #000000; font-weight: bold;">/</span>to<span style="color: #000000; font-weight: bold;">/</span>ree<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>gem <span style="color: #c20cb9; font-weight: bold;">install</span> rails ruby-debug hpricot</pre></div></div>

<p>If you run into problems, make sure you&#8217;re tailing Apache&#8217;s error log and not just the Rails log, b/c that&#8217;s where Passenger will moan about its problems.</p>
<p>As I said, memory gains seem non-existent on our Ubuntu production machine, which is weird because I saw a 25% reduction in memory usage on my Macbook. </p>
]]></content:encoded>
			<wfw:commentRss>http://kueda.net/blog/2009/08/28/moving-a-rails-app-to-ruby-enterprise-edition/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Active Record Model Adapters</title>
		<link>http://kueda.net/blog/2008/09/09/active-record-model-adapters/</link>
		<comments>http://kueda.net/blog/2008/09/09/active-record-model-adapters/#comments</comments>
		<pubDate>Tue, 09 Sep 2008 22:32:25 +0000</pubDate>
		<dc:creator>Ken-ichi</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[designpatterns]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://kueda.net/?p=208</guid>
		<description><![CDATA[I recently refactored some code in iNaturalist that fetches taxon names from external name providers like uBio and the Catalogue of Life. They return names and classification data that are similar but (of course) not identical to ActiveRecord models we use in iNat, so I figured I&#8217;d write adapters for them, and I thought a [...]]]></description>
			<content:encoded><![CDATA[<p>I recently refactored some code in <a href="http://inaturalist.org">iNaturalist</a> that fetches taxon names from external name providers like <a href="http://ubio.org">uBio</a> and the <a href="http://catalogueoflife.org">Catalogue of Life</a>.  They return names and classification data that are similar but (of course) not identical to ActiveRecord models we use in iNat, so I figured I&#8217;d write adapters for them, and I thought a really smart solution would be to subclass the models themselves, simply overriding the attributes with getters that mined a private instance variable holding an XML response from one of the web services.  Big mistake.  ActiveRecord mixes in all kinds of magic into the models that doesn&#8217;t necessarily get passed on to child classes.  I ran into all sorts of fun errors and problems until I remembered the Adapter implementation described <a href="http://www.scribd.com/doc/396559/gof-patterns-in-ruby">here</a>, which takes a much more sensible approach: don&#8217;t sublcass, and instead hold an internal copy of the adaptee, passing calls to anything you don&#8217;t want to override to the adaptee.</p>
<p><span id="more-208"></span>The only real &#8220;gotcha&#8221; is that <code>ActiveRecord::Base</code> overrides some of <code>Object</code>&#8216;s methods, so you need to delegate those to the adaptee as well.  I just delegated them all, though there may be some unforeseen consequences in this, I don&#8217;t know.</p>
<p>Anyway, here&#8217;s my solution: a model adapter module:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#008000; font-style:italic;">#</span>
<span style="color:#008000; font-style:italic;"># Module for ActiveRecord model adapters.</span>
<span style="color:#008000; font-style:italic;">#</span>
<span style="color:#008000; font-style:italic;"># Usage:</span>
<span style="color:#008000; font-style:italic;">#   class YourModelAdapter</span>
<span style="color:#008000; font-style:italic;">#     include ModelAdapter</span>
<span style="color:#008000; font-style:italic;">#     alias :your_model :adaptee # optional</span>
<span style="color:#008000; font-style:italic;">#     </span>
<span style="color:#008000; font-style:italic;">#     def initialize</span>
<span style="color:#008000; font-style:italic;">#       @adaptee = YourModel.new # required!</span>
<span style="color:#008000; font-style:italic;">#     end</span>
<span style="color:#008000; font-style:italic;">#     </span>
<span style="color:#008000; font-style:italic;">#     def some_attribute</span>
<span style="color:#008000; font-style:italic;">#       do_something_different</span>
<span style="color:#008000; font-style:italic;">#     end</span>
<span style="color:#008000; font-style:italic;">#   end</span>
<span style="color:#008000; font-style:italic;">#</span>
<span style="color:#9966CC; font-weight:bold;">module</span> ModelAdapter
  attr_accessor <span style="color:#ff3333; font-weight:bold;">:adaptee</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> method_missing<span style="color:#006600; font-weight:bold;">&#40;</span>method, <span style="color:#006600; font-weight:bold;">*</span>args<span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#0066ff; font-weight:bold;">@adaptee</span>.<span style="color:#9900CC;">respond_to</span>? method
      <span style="color:#0066ff; font-weight:bold;">@adaptee</span>.<span style="color:#9900CC;">send</span><span style="color:#006600; font-weight:bold;">&#40;</span>method, <span style="color:#006600; font-weight:bold;">*</span>args<span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#9966CC; font-weight:bold;">else</span>
      <span style="color:#CC0066; font-weight:bold;">raise</span> <span style="color:#CC00FF; font-weight:bold;">NoMethodError</span>, <span style="color:#996600;">&quot;#{self.class} hasn't implemented #{method}&quot;</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  <span style="color:#008000; font-style:italic;"># Redirect calls to public methods in Object to the adaptee</span>
  <span style="color:#CC00FF; font-weight:bold;">Object</span>.<span style="color:#9900CC;">methods</span>.<span style="color:#9900CC;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>method_name<span style="color:#006600; font-weight:bold;">|</span>
    define_method<span style="color:#006600; font-weight:bold;">&#40;</span>method_name.<span style="color:#9900CC;">to_sym</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>args<span style="color:#006600; font-weight:bold;">|</span>
      <span style="color:#0066ff; font-weight:bold;">@adaptee</span>.<span style="color:#9900CC;">send</span><span style="color:#006600; font-weight:bold;">&#40;</span>method_name.<span style="color:#9900CC;">to_sym</span>, <span style="color:#006600; font-weight:bold;">*</span>args<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:#9966CC; font-weight:bold;">end</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://kueda.net/blog/2008/09/09/active-record-model-adapters/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Rails Authenticity Tokens and Facebooker</title>
		<link>http://kueda.net/blog/2008/07/17/rails-authenticity-tokens-and-facebooker/</link>
		<comments>http://kueda.net/blog/2008/07/17/rails-authenticity-tokens-and-facebooker/#comments</comments>
		<pubDate>Thu, 17 Jul 2008 18:36:36 +0000</pubDate>
		<dc:creator>Ken-ichi</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[facebook]]></category>
		<category><![CDATA[facebooker]]></category>
		<category><![CDATA[rails]]></category>

		<guid isPermaLink="false">http://kueda.net/?p=5</guid>
		<description><![CDATA[In case you&#8217;re working through Developing Facebook Platform Applications with Rails, you might have run into problems with authenticity tokens and FBML forms.  Quick dumb fix to save you 2 seconds: &#60;fb:fbml&#62; &#60;fb:request-form action=&#34;&#60;%= new_invitation_path %&#62;&#34; method=&#34;POST&#34; invite=&#34;true&#34; type=&#34;Karate Poke&#34; content=&#34;YAYS I added this facebbok app&#34;&#62; &#60;fb:multi-friend-selector showborder=&#34;false&#34; actiontext=&#34;Invite your friends to use Karate Poke&#34; [...]]]></description>
			<content:encoded><![CDATA[<p>In case you&#8217;re working through <a href="http://www.pragprog.com/titles/mmfacer/developing-facebook-platform-applications-with-rails">Developing Facebook Platform Applications with Rails</a>, you might have run into <a href="http://rubyforge.org/pipermail/facebooker-talk/2008-June/thread.html#650">problems</a> with authenticity tokens and FBML forms.  Quick dumb fix to save you 2 seconds:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;fb:fbml<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;fb:request-form</span></span>
<span style="color: #009900;">    <span style="color: #000066;">action</span>=<span style="color: #ff0000;">&quot;&lt;%= new_invitation_path %&gt;</span></span>&quot;
    method=&quot;POST&quot;
    invite=&quot;true&quot;
    type=&quot;Karate Poke&quot;
    content=&quot;YAYS I added this facebbok app&quot;&gt;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;fb:multi-friend-selector</span></span>
<span style="color: #009900;">      <span style="color: #000066;">showborder</span>=<span style="color: #ff0000;">&quot;false&quot;</span></span>
<span style="color: #009900;">      <span style="color: #000066;">actiontext</span>=<span style="color: #ff0000;">&quot;Invite your friends to use Karate Poke&quot;</span></span>
<span style="color: #009900;">    <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;">&lt;%= hidden_field_tag :authenticity_token, form_authenticity_token %<span style="color: #000000; font-weight: bold;">&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/fb:request-form<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/fb:fbml<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://kueda.net/blog/2008/07/17/rails-authenticity-tokens-and-facebooker/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

