<?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>MSKYNET BLOG &#187; overwrite_params</title>
	<atom:link href="http://www.mskynet.com/msky-blog/tag/overwrite_params/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.mskynet.com/msky-blog</link>
	<description>The future of mobile is here...</description>
	<lastBuildDate>Thu, 03 Jun 2010 05:49:51 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.5</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Rails URL Redirect</title>
		<link>http://www.mskynet.com/msky-blog/2010/01/19/rails-url-redirect/</link>
		<comments>http://www.mskynet.com/msky-blog/2010/01/19/rails-url-redirect/#comments</comments>
		<pubDate>Wed, 20 Jan 2010 06:20:17 +0000</pubDate>
		<dc:creator>Lee</dc:creator>
				<category><![CDATA[MSKYNET]]></category>
		<category><![CDATA[Technical Development]]></category>
		<category><![CDATA[overwrite_params]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[url rewrite]]></category>

		<guid isPermaLink="false">http://www.mskynet.com/msky-blog/?p=200</guid>
		<description><![CDATA[redirect_to :overwrite_params =&#62; {:controller=&#62;&#8217;survey&#8217;, :action=&#62;&#8217;handle_single_scan&#8217;}
Here&#8217;s a little trick I discovered recently.
I wanted to rewrite a url, forwarding a request to [...]]]></description>
			<content:encoded><![CDATA[<div id="_mcePaste" style="overflow: hidden; position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px;">redirect_to :overwrite_params =&gt; {:controller=&gt;&#8217;survey&#8217;, :action=&gt;&#8217;handle_single_scan&#8217;}</div>
<p>Here&#8217;s a little trick I discovered recently.<img class="alignright" title="http://msky-blog.s3.amazonaws.com/rails/ror_logo.png" src="http://msky-blog.s3.amazonaws.com/rails/ror_logo.png" alt="" width="104" height="124" /></p>
<p>I wanted to rewrite a url, forwarding a request to another controller, with all the other parameters intact. Rather than define each individual parameter, I found that rails has a built in API to preserve the existing URL with just a few fields specified.</p>
<p>For instance, say I had a request going to http://www.mskynet.com/foo/log?id=123&amp;param=456, and I wanted to redirect to http://www.mskynet.com/bar/do_work?id=123&amp;param=456, I could do the following:</p>
<blockquote><p>redirect_to :overwrite_params =&gt; {:controller=&gt;&#8217;bar&#8217;, :action=&gt;&#8217;do_work&#8217;}</p></blockquote>
<p>This syntax would let you overwrite any of the parameters that you want to change and keep everything else the same.</p>
<p>If I just wanted to overwrite the parameter &#8216;id&#8217; but keep the controller and action, I could do:</p>
<blockquote><p>redirect_to :overwrite_params =&gt; {:id=&gt;&#8217;234&#8242;}</p></blockquote>
<p>Check out the :overwrite_params option here: <a title="http://api.rubyonrails.org/classes/ActionController/Base.html#M000649" href="http://api.rubyonrails.org/classes/ActionController/Base.html#M000649">http://api.rubyonrails.org/classes/ActionController/Base.html#M000649</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.mskynet.com/msky-blog/2010/01/19/rails-url-redirect/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
