<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Workin' on it. &#187; hack</title>
	<atom:link href="http://jameshalberg.wordpress.com/tag/hack/feed/" rel="self" type="application/rss+xml" />
	<link>http://jameshalberg.wordpress.com</link>
	<description></description>
	<lastBuildDate>Sat, 19 Nov 2011 14:15:48 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='jameshalberg.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Workin' on it. &#187; hack</title>
		<link>http://jameshalberg.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://jameshalberg.wordpress.com/osd.xml" title="Workin&#039; on it." />
	<atom:link rel='hub' href='http://jameshalberg.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Nice(r) Hash treatment for URLs</title>
		<link>http://jameshalberg.wordpress.com/2007/11/14/nicer-hash-treatment-for-urls/</link>
		<comments>http://jameshalberg.wordpress.com/2007/11/14/nicer-hash-treatment-for-urls/#comments</comments>
		<pubDate>Wed, 14 Nov 2007 09:53:08 +0000</pubDate>
		<dc:creator>Jim</dc:creator>
				<category><![CDATA[rails]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[hack]]></category>
		<category><![CDATA[url_for]]></category>

		<guid isPermaLink="false">http://jameshalberg.wordpress.com/2007/11/14/nicer-hash-treatment-for-urls/</guid>
		<description><![CDATA[Isn&#8217;t it nice how Rails lets you add form elements using the convention: store[manager] = Bob Smith store[location][state] = Wisconsin store[location][zip] = 53590 And easily process them on the server side with something like: Store.new(params[:store]) So, why does this: link_to &#8230; <a href="http://jameshalberg.wordpress.com/2007/11/14/nicer-hash-treatment-for-urls/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jameshalberg.wordpress.com&amp;blog=160606&amp;post=93&amp;subd=jameshalberg&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Isn&#8217;t it nice how Rails lets you add form elements using the convention:</p>
<p>store[manager] = Bob Smith<br />
store[location][state] = Wisconsin<br />
store[location][zip] = 53590</p>
<p>And easily process them on the server side with something like:<br />
Store.new(params[:store])</p>
<p>So, why does this:<br />
link_to &#8220;Store&#8221;, :controller =&gt; :store, :action =&gt; :show, :store =&gt; { :manager =&gt; &#8220;Bob Smith&#8221;, :location =&gt; { :state =&gt; &#8220;Wisconsin&#8221;, :zip =&gt; 53590 } }</p>
<p>output something stupid like this:</p>
<p>http://localhost:3000/case/1/store/show?store=locationstateWisconsinzip53590managerBob+Smith</p>
<p>when what I&#8217;d like is something like:</p>
<p>http://localhost:3000/store/show?store%5Blocation%5D%5Bstate%5D=Wisconsin&#038;store%5Blocation%5D%5Bzip%5D=53590&#038;store%5Bmanager%5D=Bob+Smith</p>
<p>Well, without further ado, I give you the url_for hack to make it happen (note: For a widespread solution this would need to do a bit more&#8230; escape things, handle some different object types, handle more than 1 layer of hashed values, etc&#8230; but you get the idea)</p>
<p><a title="url_for_hack2.png" href="http://jameshalberg.files.wordpress.com/2007/11/url_for_hack2.png"><img src="http://jameshalberg.files.wordpress.com/2007/11/url_for_hack2.png?w=500" alt="url_for_hack2.png" /></a></p>
<p>Putting this in url_for has other benefits since lots of things depend on it.  For example, now you can do:</p>
<p>redirect_to :action =&gt; :show,  :store =&gt; { :manager =&gt; &#8220;Bob Smith&#8221;, :location =&gt; { :state =&gt; &#8220;Wisconsin&#8221;, :zip =&gt; 53590 } }</p>
<p>This is especially handy if you&#8217;d like an action to &#8220;hand off&#8221; some of the params that it&#8217;s received via a redirect.</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/jameshalberg.wordpress.com/93/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/jameshalberg.wordpress.com/93/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jameshalberg.wordpress.com/93/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jameshalberg.wordpress.com/93/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/jameshalberg.wordpress.com/93/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/jameshalberg.wordpress.com/93/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/jameshalberg.wordpress.com/93/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/jameshalberg.wordpress.com/93/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/jameshalberg.wordpress.com/93/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/jameshalberg.wordpress.com/93/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/jameshalberg.wordpress.com/93/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/jameshalberg.wordpress.com/93/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/jameshalberg.wordpress.com/93/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/jameshalberg.wordpress.com/93/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/jameshalberg.wordpress.com/93/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/jameshalberg.wordpress.com/93/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jameshalberg.wordpress.com&amp;blog=160606&amp;post=93&amp;subd=jameshalberg&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://jameshalberg.wordpress.com/2007/11/14/nicer-hash-treatment-for-urls/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">jameshalberg</media:title>
		</media:content>

		<media:content url="http://jameshalberg.files.wordpress.com/2007/11/url_for_hack2.png" medium="image">
			<media:title type="html">url_for_hack2.png</media:title>
		</media:content>
	</item>
	</channel>
</rss>
