<?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>BigSmoke &#187; Rails</title>
	<atom:link href="http://blog.bigsmoke.us/tag/rails/feed" rel="self" type="application/rss+xml" />
	<link>http://blog.bigsmoke.us</link>
	<description>Smokes your problems, coughs fresh air.</description>
	<lastBuildDate>Sat, 04 Feb 2012 18:03:39 +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>Silent change in URLs of Ruby on Rails svn repository</title>
		<link>http://blog.bigsmoke.us/2009/02/19/silent-change-in-urls-of-ruby-on-rails-svn-repository</link>
		<comments>http://blog.bigsmoke.us/2009/02/19/silent-change-in-urls-of-ruby-on-rails-svn-repository#comments</comments>
		<pubDate>Thu, 19 Feb 2009 13:41:11 +0000</pubDate>
		<dc:creator>halfgaar</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[Subversion]]></category>
		<category><![CDATA[svn]]></category>
		<category><![CDATA[URL]]></category>

		<guid isPermaLink="false">http://blog.bigsmoke.us/?p=413</guid>
		<description><![CDATA[]]></description>
			<content:encoded><![CDATA[<p>
I don&#8217;t know why, but everything associated with Ruby on Rails seems to change all the time, without notice, or (in the case of URLs) without redirect.
</p>

<p>
We used <tt>http://svn.rubyonrails.org/</tt>rails for our <tt>svn:external</tt> deployment of rails 1.2.6. But that suddenly stopped working. The Ruby on Rails weblog doesn&#8217;t contain any information on it (that I can find), going to <tt>svn.rubyonrails.org</tt> with my web browser yielded just the front page of the weblog and Googling didn&#8217;t help much. That is, until I accidentally found <tt>http://dev.rubyonrails.org/svn/rails</tt>.
</p>

<p>
So, I changed the <tt>svn:externals</tt> from &#8220;<tt>rails http://svn.rubyonrails.org/rails/tags/rel_1-2-6/</tt>&#8221; to &#8220;<tt>rails http://dev.rubyonrails.org/svn/rails/tags/rel_1-2-6/</tt>&#8221; and now it works again.
</p>]]></content:encoded>
			<wfw:commentRss>http://blog.bigsmoke.us/2009/02/19/silent-change-in-urls-of-ruby-on-rails-svn-repository/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Native PostgreSQL authentication in Rails with rails-psql-auth</title>
		<link>http://blog.bigsmoke.us/2007/07/16/rails-psql-auth</link>
		<comments>http://blog.bigsmoke.us/2007/07/16/rails-psql-auth#comments</comments>
		<pubDate>Mon, 16 Jul 2007 13:58:13 +0000</pubDate>
		<dc:creator>Rowan Rodrik</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[HTTP]]></category>
		<category><![CDATA[PostgreSQL]]></category>
		<category><![CDATA[Rails]]></category>

		<guid isPermaLink="false">http://blog.bigsmoke.us/2007/07/16/rails-psql-auth</guid>
		<description><![CDATA[]]></description>
			<content:encoded><![CDATA[<p>A while ago, I wrote a <a href="http://rubyforge.org/projects/rails-psql-auth/">PostgreSQL auth</a> plugin for <a href="http://www.rubyonrails.org/">Rails</a>. The plugin basically defers all authentication and authorization worries to the database layer where they are supposed to be taken care of anyway.</p>

<p>Using this plugin, the user is asked for his or her credentials using a HTTP Basic authentication challenge. (The code for this is adapted from <a href="http://www.codahale.com/">Coda Hale</a>&#8216;s <a href="http://blog.codahale.com/2006/05/11/basic-http-authentication-with-rails-simple_http_auth/">Basic HTTP authentication plugin</a>.) It&#8217;s possible to specify a <tt>guest_username</tt> in the <tt>database.yml</tt> which will be used as a fall-back if no credentials are supplied. After successful login or if a guest user is found, the plugin will make sure that all database operations run as that user. If any operation fails due to insufficient user rights, the user will be prompted for a username/password pair again.</p>

<p>Detailed and up-to-date documentation for the plugin can always be found at the plugin&#8217;s <a href="http://rails-psql-auth.rubyforge.org/">homepage</a>. Go to the plugin&#8217;s <a href="http://rubyforge.org/projects/rails-psql-auth/">project page</a> for getting help or for reporting issues with the plugin.</p>]]></content:encoded>
			<wfw:commentRss>http://blog.bigsmoke.us/2007/07/16/rails-psql-auth/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Nested hashes derail Rails&#8217; url_for helpers</title>
		<link>http://blog.bigsmoke.us/2007/02/19/nested-hashes-derail-rails-url-helpers</link>
		<comments>http://blog.bigsmoke.us/2007/02/19/nested-hashes-derail-rails-url-helpers#comments</comments>
		<pubDate>Mon, 19 Feb 2007 18:42:47 +0000</pubDate>
		<dc:creator>Rowan Rodrik</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[link_to]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[URL]]></category>
		<category><![CDATA[url_for]]></category>

		<guid isPermaLink="false">http://blog.bigsmoke.us/2007/02/19/nested-hashes-url-helpers-on-rails</guid>
		<description><![CDATA[]]></description>
			<content:encoded><![CDATA[<p>While working on the Sicirec PostgreSQL database front-end today, I had to pass a lot of nested parameters to a <tt><a href="http://api.rubyonrails.org/classes/ActionView/Helpers/UrlHelper.html#M000485">link_to</a></tt> helper in Rails. Software being what it is, this didn&#8217;t work.</p>

<p>There are a few patches awaiting acceptance. The <a href="http://dev.rubyonrails.org/ticket/4947">most promising</a> of these patches was part of an open Trac ticket. Because we use Rails as an svn external, applying the patch myself wouldn&#8217;t work when deploying unless I&#8217;d create a vendor branch for Rails in our own repository. Hoping that someone had forgotten to close the ticket, I first tried to upgrade to Rails 1.2.2, which was about time anyway because we were still in the 1.1 branch. The upgrade went fine but didn&#8217;t fix the problem.</p>

<p>Next, I tried to integrate the patch by redefining the methods changed by the patch in our <tt>lib/</tt> directory. When this didn&#8217;t work, I decided to simply do some flattening of the hash myself for this one particular case.</p>

<p>A bit of <a href="http://www.google.com/search?q=url_for+nested+hashes">googling around</a> gave me <a href="http://www.ruby-forum.com/topic/72705">many</a> <a href="http://www.railsweenie.com/forums/1/topics/131">clues</a> <a href="http://blog.bigsmoke.us/wp-admin/post.php?action=edit&#038;post=13">that</a> the problem has cost a lot of people lots of time already.</p>

<p>Eventually, I settled with a derivate of <a href="http://marklunds.com/articles/one/314">some code</a> by <a href="http://marklunds.com/">Peter Marklund</a> to flatten my hashes:

<pre class="ruby"><span style="color:#9966CC; font-weight:bold;">class</span> Hash
  <span style="color:#008000; font-style:italic;"># Flatten a hash into a flat form suitable for an URL.</span>
  <span style="color:#008000; font-style:italic;"># Accepts as an optional parameter an array of names that pretend to be the ancestor key names.</span>
  <span style="color:#008000; font-style:italic;">#</span>
  <span style="color:#008000; font-style:italic;"># Example 1:</span>
  <span style="color:#008000; font-style:italic;">#</span>
  <span style="color:#008000; font-style:italic;">#   { 'animals' =&gt; {</span>
  <span style="color:#008000; font-style:italic;">#       'fish' =&gt; { 'legs' =&gt; 0, 'sound' =&gt; 'Blub' }</span>
  <span style="color:#008000; font-style:italic;">#       'cat' =&gt; { 'legs' =&gt; 4, 'sound' =&gt; 'Miaow' }</span>
  <span style="color:#008000; font-style:italic;">#   }.flatten_for_url</span>
  <span style="color:#008000; font-style:italic;">#</span>
  <span style="color:#008000; font-style:italic;">#   # =&gt; { 'animals[fish][legs]'  =&gt; 0,</span>
  <span style="color:#008000; font-style:italic;">#          'animals[fish][sound]' =&gt; 'Blub',</span>
  <span style="color:#008000; font-style:italic;">#          'animals[cat][legs]'   =&gt; 4,</span>
  <span style="color:#008000; font-style:italic;">#          'animals[cat][sound]'  =&gt; 'Miaow'</span>
  <span style="color:#008000; font-style:italic;">#        }</span>
  <span style="color:#008000; font-style:italic;">#</span>
  <span style="color:#008000; font-style:italic;"># Example 2:</span>
  <span style="color:#008000; font-style:italic;">#</span>
  <span style="color:#008000; font-style:italic;">#   {'color' =&gt; 'blue'}.flatten_for_url( %w(world things) )  # =&gt; {'world[things][color]' =&gt; 'blue'}</span>
  <span style="color:#008000; font-style:italic;">#</span>
  <span style="color:#9966CC; font-weight:bold;">def</span> flatten_for_url<span style="color:#006600; font-weight:bold;">&#40;</span>ancestor_names = <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    flat_hash = Hash.<span style="color:#9900CC;">new</span>
&nbsp;
    each <span style="color:#9966CC; font-weight:bold;">do</span> |key, value|
      names = <span style="color:#CC0066; font-weight:bold;">Array</span>.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span>ancestor_names<span style="color:#006600; font-weight:bold;">&#41;</span>
      names &lt;&lt; key
&nbsp;
      <span style="color:#9966CC; font-weight:bold;">if</span> value.<span style="color:#9900CC;">is_a</span>?<span style="color:#006600; font-weight:bold;">&#40;</span>Hash<span style="color:#006600; font-weight:bold;">&#41;</span>
        flat_hash.<span style="color:#9900CC;">merge</span>!<span style="color:#006600; font-weight:bold;">&#40;</span>value.<span style="color:#9900CC;">flatten_for_url</span><span style="color:#006600; font-weight:bold;">&#40;</span>names<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;">else</span>
        flat_key = names.<span style="color:#9900CC;">shift</span>.<span style="color:#9900CC;">to_s</span>.<span style="color:#9900CC;">dup</span>
        names.<span style="color:#9900CC;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> |name|
          flat_key &lt;&lt; <span style="color:#996600;">&quot;[#{name}]&quot;</span>
        <span style="color:#9966CC; font-weight:bold;">end</span>
        flat_key &lt;&lt; <span style="color:#996600;">&quot;[]&quot;</span> <span style="color:#9966CC; font-weight:bold;">if</span> value.<span style="color:#9900CC;">is_a</span>?<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC0066; font-weight:bold;">Array</span><span style="color:#006600; font-weight:bold;">&#41;</span>
        flat_hash<span style="color:#006600; font-weight:bold;">&#91;</span>flat_key<span style="color:#006600; font-weight:bold;">&#93;</span> = value
      <span style="color:#9966CC; font-weight:bold;">end</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
    flat_hash
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre>

<p>As you can see, I turned my code into a single method of the <tt>Hash</tt> class. It can be used simply in any <tt>url_for</tt> (based) call as in the following example:</p>

<pre class="ruby">url_for <span style="color:#006600; font-weight:bold;">&#123;</span>
    :controller =&gt; 'post',
    :action =&gt; 'new',
    'author' =&gt; <span style="color:#006600; font-weight:bold;">&#123;</span>'name' =&gt; 'Rowan', 'gender' =&gt; 'm'<span style="color:#006600; font-weight:bold;">&#125;</span>
  <span style="color:#006600; font-weight:bold;">&#125;</span>.<span style="color:#9900CC;">flatten_for_url</span>
  <span style="color:#008000; font-style:italic;"># =&gt; /post/new?author[name]=Rowan&amp;author[gender]=m </span></pre>

<p>Now if only some Rails developer would commit <a href="http://dev.rubyonrails.org/ticket/4947">the patch</a> already.</p>]]></content:encoded>
			<wfw:commentRss>http://blog.bigsmoke.us/2007/02/19/nested-hashes-derail-rails-url-helpers/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

