<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: Better Redirects in Rails</title>
	<atom:link href="http://ethilien.net/archives/better-redirects-in-rails/feed/" rel="self" type="application/rss+xml" />
	<link>http://ethilien.net/archives/better-redirects-in-rails/</link>
	<description>I need to redo this site...</description>
	<lastBuildDate>Wed, 09 Jun 2010 04:30:19 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: &#304;zzet Emre Kutlu</title>
		<link>http://ethilien.net/archives/better-redirects-in-rails/comment-page-1/#comment-23374</link>
		<dc:creator>&#304;zzet Emre Kutlu</dc:creator>
		<pubDate>Thu, 14 May 2009 13:51:56 +0000</pubDate>
		<guid isPermaLink="false">http://ethilien.net/archives/better-redirects-in-rails/#comment-23374</guid>
		<description>&lt;p&gt;another option for link_away method :
&lt;code&gt;def link_away(*args, &amp;block)
    original_uri = {:original_uri =&gt; request.request_uri}
    if block_given?
      options      = args.first &#124;&#124; {}
      html_options = args.second
      options.merge!(original_uri)
      link_to(options, html_options) do
        capture(&amp;block)
      end
    else
      name         = args.first
      options      = args.second &#124;&#124; {}
      html_options = args.third
      options.merge!(original_uri)
      link_to(name, options, html_options)
    end
  end&lt;/code&gt;&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>another option for link_away method :
<code>def link_away(*args, &amp;block)
    original_uri = {:original_uri =&gt; request.request_uri}
    if block_given?
      options      = args.first || {}
      html_options = args.second
      options.merge!(original_uri)
      link_to(options, html_options) do
        capture(&amp;block)
      end
    else
      name         = args.first
      options      = args.second || {}
      html_options = args.third
      options.merge!(original_uri)
      link_to(name, options, html_options)
    end
  end</code></p>]]></content:encoded>
	</item>
	<item>
		<title>By: Nathan Levitt</title>
		<link>http://ethilien.net/archives/better-redirects-in-rails/comment-page-1/#comment-12938</link>
		<dc:creator>Nathan Levitt</dc:creator>
		<pubDate>Sat, 09 Aug 2008 01:30:44 +0000</pubDate>
		<guid isPermaLink="false">http://ethilien.net/archives/better-redirects-in-rails/#comment-12938</guid>
		<description>&lt;p&gt;Thanks for the awesome article!&lt;/p&gt;

&lt;p&gt;@Adam - I love your suggestions on this. I do the same thing and it seems to work great!&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Thanks for the awesome article!</p>

<p>@Adam &#8211; I love your suggestions on this. I do the same thing and it seems to work great!</p>]]></content:encoded>
	</item>
	<item>
		<title>By: David Cotter</title>
		<link>http://ethilien.net/archives/better-redirects-in-rails/comment-page-1/#comment-11990</link>
		<dc:creator>David Cotter</dc:creator>
		<pubDate>Sat, 05 Jul 2008 14:57:24 +0000</pubDate>
		<guid isPermaLink="false">http://ethilien.net/archives/better-redirects-in-rails/#comment-11990</guid>
		<description>&lt;p&gt;@Alderete for it to work here&#039;s how I did it:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;
    def link_away(name, options = {}, html_options = nil)
      if (options.is_a?(String)) 
        options = ApplicationHelper.append_url_parameters(options, {:return&lt;/em&gt;uri =&gt; url_for(:only&lt;/em&gt;path =&gt; true)})
      else
        options = { :return_uri =&gt; url&lt;/em&gt;for(:only_path =&gt; true) }.update(options.symbolize&lt;/em&gt;keys)
      end
      link_to(name, options, html&lt;/em&gt;options)
    end&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;To append a param to the URL I use this (forgive me if there&#039;s already a function to do this which I can&#039;t find)&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;def self.append_url_parameters(url, urlparams) 
  new_params_query_string = &#039;&#039;
  first = true
  urlparams.each_pair do &#124;param, value&#124;
    new_params_query_string &lt;&lt; &#039;&amp;`&#039; unless first
    new_params_query_string &lt;&lt; &quot;#{param}=#{CGI.escape(value.to_s)}&quot;
    first = false
  end
  uri, query = url.split(&#039;?&#039;)
  if (query.blank?) 
    uri + &quot;?&quot; + new_params_query_string
  else   
    uri + &quot;?&quot; + query + &quot;&amp;&quot; + new_params_query_string
  end    
end
&lt;/code&gt;&lt;/pre&gt;
</description>
		<content:encoded><![CDATA[<p>@Alderete for it to work here&#8217;s how I did it:</p>

<pre><code>
    def link_away(name, options = {}, html_options = nil)
      if (options.is_a?(String)) 
        options = ApplicationHelper.append_url_parameters(options, {:returnuri =&gt; url_for(:onlypath =&gt; true)})
      else
        options = { :return_uri =&gt; urlfor(:only_path =&gt; true) }.update(options.symbolizekeys)
      end
      link_to(name, options, htmloptions)
    end</code></pre>

<p>To append a param to the URL I use this (forgive me if there&#8217;s already a function to do this which I can&#8217;t find)</p>

<pre><code>def self.append_url_parameters(url, urlparams) 
  new_params_query_string = ''
  first = true
  urlparams.each_pair do |param, value|
    new_params_query_string &lt;&lt; '&amp;`' unless first
    new_params_query_string &lt;&lt; "#{param}=#{CGI.escape(value.to_s)}"
    first = false
  end
  uri, query = url.split('?')
  if (query.blank?) 
    uri + "?" + new_params_query_string
  else   
    uri + "?" + query + "&amp;" + new_params_query_string
  end    
end
</code></pre>]]></content:encoded>
	</item>
	<item>
		<title>By: Adam</title>
		<link>http://ethilien.net/archives/better-redirects-in-rails/comment-page-1/#comment-10699</link>
		<dc:creator>Adam</dc:creator>
		<pubDate>Fri, 11 Apr 2008 15:11:56 +0000</pubDate>
		<guid isPermaLink="false">http://ethilien.net/archives/better-redirects-in-rails/#comment-10699</guid>
		<description>&lt;p&gt;We do something similar by marking certain points in an application as return points. &lt;/p&gt;

&lt;pre&gt;&lt;code&gt;before_filter :mark_return_point :only =&gt;[x,z]
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Which does exactly the same thing and marks a return parameter in the session, we just have a &lt;/p&gt;

&lt;pre&gt;&lt;code&gt;return_to_last_point 
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;then whenever an action like an update completes redirects to the last point someone went through. &lt;/p&gt;

&lt;p&gt;Not sure which I prefer, our current way keeps the logic of the flow inside the controller&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>We do something similar by marking certain points in an application as return points. </p>

<pre><code>before_filter :mark_return_point <img src='http://ethilien.net/wp-includes/images/smilies/icon_surprised.gif' alt=':o' class='wp-smiley' /> nly =&gt;[x,z]
</code></pre>

<p>Which does exactly the same thing and marks a return parameter in the session, we just have a </p>

<pre><code>return_to_last_point 
</code></pre>

<p>then whenever an action like an update completes redirects to the last point someone went through. </p>

<p>Not sure which I prefer, our current way keeps the logic of the flow inside the controller</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Alderete</title>
		<link>http://ethilien.net/archives/better-redirects-in-rails/comment-page-1/#comment-10686</link>
		<dc:creator>Alderete</dc:creator>
		<pubDate>Thu, 10 Apr 2008 10:30:13 +0000</pubDate>
		<guid isPermaLink="false">http://ethilien.net/archives/better-redirects-in-rails/#comment-10686</guid>
		<description>&lt;p&gt;On further testing, neither the original nor my altered version of the helper handle the case of a generated show link, which simply passes in an ActiveRecord object:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;&lt;%= link_away h(person.display_name), person %&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;(person also gets passed for generated delete links.)&lt;/p&gt;

&lt;p&gt;Not really sure what the answer is, except to only use link_away for edit links.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>On further testing, neither the original nor my altered version of the helper handle the case of a generated show link, which simply passes in an ActiveRecord object:</p>

<pre><code>&lt;%= link_away h(person.display_name), person %&gt;
</code></pre>

<p>(person also gets passed for generated delete links.)</p>

<p>Not really sure what the answer is, except to only use link_away for edit links.</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Alderete</title>
		<link>http://ethilien.net/archives/better-redirects-in-rails/comment-page-1/#comment-10684</link>
		<dc:creator>Alderete</dc:creator>
		<pubDate>Thu, 10 Apr 2008 10:11:15 +0000</pubDate>
		<guid isPermaLink="false">http://ethilien.net/archives/better-redirects-in-rails/#comment-10684</guid>
		<description>&lt;p&gt;I notice that this isn&#039;t quite a drop-in replacement for the link_to code that is generated by the Rails 2.0 scaffolding generator, specifically, the URL helpers generated by using map.resources in routes.rb, e.g.:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;&lt;%= link_away &#039;Edit&#039;, edit_person_path(@person) %&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Will fail with the error &quot;undefined method `symbolize_keys&#039; for &quot;/people/1/edit&quot;:String&quot;&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;def link_away(name, options = {}, html_options = nil)
    link = case options
        when String
            link_to(name, options + &quot;?return_uri=&quot; + url_for(:only_path =&gt; true), html_options)
        else
            link_to(name, { :return_uri =&gt; url_for(:only_path =&gt; true) }.update(options.symbolize_keys), html_options)
        end
end
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;But that&#039;s fairly unsatisfying, if for no reason than it will add an extra &quot;?&quot; to the URL if there are already parameters in it. (My Ruby-fu is weak.)&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>I notice that this isn&#8217;t quite a drop-in replacement for the link_to code that is generated by the Rails 2.0 scaffolding generator, specifically, the URL helpers generated by using map.resources in routes.rb, e.g.:</p>

<pre><code>&lt;%= link_away 'Edit', edit_person_path(@person) %&gt;
</code></pre>

<p>Will fail with the error &#8220;undefined method `symbolize_keys&#8217; for &#8220;/people/1/edit&#8221;:String&#8221;</p>

<pre><code>def link_away(name, options = {}, html_options = nil)
    link = case options
        when String
            link_to(name, options + "?return_uri=" + url_for(:only_path =&gt; true), html_options)
        else
            link_to(name, { :return_uri =&gt; url_for(:only_path =&gt; true) }.update(options.symbolize_keys), html_options)
        end
end
</code></pre>

<p>But that&#8217;s fairly unsatisfying, if for no reason than it will add an extra &#8220;?&#8221; to the URL if there are already parameters in it. (My Ruby-fu is weak.)</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Anthony</title>
		<link>http://ethilien.net/archives/better-redirects-in-rails/comment-page-1/#comment-10439</link>
		<dc:creator>Anthony</dc:creator>
		<pubDate>Wed, 26 Mar 2008 23:34:42 +0000</pubDate>
		<guid isPermaLink="false">http://ethilien.net/archives/better-redirects-in-rails/#comment-10439</guid>
		<description>&lt;p&gt;Very nice. Simple, basic, almost obvious. But really helps to tighten up recurring crap in controller code.&lt;/p&gt;

&lt;p&gt;Thanks for sharing!&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Very nice. Simple, basic, almost obvious. But really helps to tighten up recurring crap in controller code.</p>

<p>Thanks for sharing!</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Dan</title>
		<link>http://ethilien.net/archives/better-redirects-in-rails/comment-page-1/#comment-10437</link>
		<dc:creator>Dan</dc:creator>
		<pubDate>Wed, 26 Mar 2008 22:22:27 +0000</pubDate>
		<guid isPermaLink="false">http://ethilien.net/archives/better-redirects-in-rails/#comment-10437</guid>
		<description>&lt;p&gt;Very handy ideas!&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Very handy ideas!</p>]]></content:encoded>
	</item>
	<item>
		<title>By: DHH</title>
		<link>http://ethilien.net/archives/better-redirects-in-rails/comment-page-1/#comment-10379</link>
		<dc:creator>DHH</dc:creator>
		<pubDate>Sun, 23 Mar 2008 16:17:15 +0000</pubDate>
		<guid isPermaLink="false">http://ethilien.net/archives/better-redirects-in-rails/#comment-10379</guid>
		<description>&lt;p&gt;Those are some neat patterns. You should wrap them up in a plugin.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Those are some neat patterns. You should wrap them up in a plugin.</p>]]></content:encoded>
	</item>
</channel>
</rss>
