<?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: Rails fixies: JSON as input, See Other and [].to_xml</title>
	<atom:link href="http://labnotes.org/2007/10/23/rails-fixies-json-as-input-see-other-and-to_xml/feed/" rel="self" type="application/rss+xml" />
	<link>http://labnotes.org/2007/10/23/rails-fixies-json-as-input-see-other-and-to_xml/</link>
	<description></description>
	<lastBuildDate>Tue, 15 May 2012 02:41:51 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
	<item>
		<title>By: EP</title>
		<link>http://labnotes.org/2007/10/23/rails-fixies-json-as-input-see-other-and-to_xml/comment-page-1/#comment-141419</link>
		<dc:creator>EP</dc:creator>
		<pubDate>Fri, 26 Sep 2008 22:59:50 +0000</pubDate>
		<guid isPermaLink="false">http://blog.labnotes.org/2007/10/23/rails-fixies-json-as-input-see-other-and-to_xml/#comment-141419</guid>
		<description>Sorry for raising this from the dead a year after the fact but I was investigating this issue and want to thank you for sharing your thoughts.

I&#039;d also like to add my feedback, since you asked :)

In reference to #3, 303 See Other, I feel that altering the behaviour of redirect_to could be a little murky as you are changing something that is very well know. No Rails developer running your code and examining the output would have any idea why they are seeing a 303 status and not a 301. Even worse, because the redirect_to method is so ubiquitous would they even suspect that it wouldn&#039;t output what it always outputs? 

Changing something which is well understood is never a good idea IMHO. I would rather see different flavors of redirect_to like see_other() or redirect_to_other() which make it obvious to the reader that what is being done is not redirect_to but something else, similar but different.

Rather than redirect_to(..., :status =&gt; :see_other) which sends an empty response I prefer to use:

def redirect_to_other(location)
  render(:inline =&gt; &quot;......&quot;, :layout =&gt; false, :status =&gt; :see_other, :location =&gt; location)
end

or similar.

This implementation more closely satisfies the spec which states a 303 SHOULD include a hypertext note with a link to the new location in the response body. Both work, it&#039;s optional, but what the hell. If you&#039;re going to do it anyway why not.

I&#039;ve bunched my multi-flavored redirect_to_...() helpers as a module and include it in ApplicationController:

redirect_permanently_to(...) # =&gt; 301
redirect_to_other(...) # =&gt; 303
redirect_temporarily_to(...) # =&gt; 307

and use the stock redirect_to method for 302 redirects as written. This gets rid of the :status =&gt; ### ugliness too in the same way I use named_scope in my models.

Cheers</description>
		<content:encoded><![CDATA[<p>Sorry for raising this from the dead a year after the fact but I was investigating this issue and want to thank you for sharing your thoughts.</p>
<p>I&#8217;d also like to add my feedback, since you asked :)</p>
<p>In reference to #3, 303 See Other, I feel that altering the behaviour of redirect_to could be a little murky as you are changing something that is very well know. No Rails developer running your code and examining the output would have any idea why they are seeing a 303 status and not a 301. Even worse, because the redirect_to method is so ubiquitous would they even suspect that it wouldn&#8217;t output what it always outputs? </p>
<p>Changing something which is well understood is never a good idea IMHO. I would rather see different flavors of redirect_to like see_other() or redirect_to_other() which make it obvious to the reader that what is being done is not redirect_to but something else, similar but different.</p>
<p>Rather than redirect_to(&#8230;, :status =&gt; :see_other) which sends an empty response I prefer to use:</p>
<p>def redirect_to_other(location)<br />
  render(:inline =&gt; &#8220;&#8230;&#8230;&#8221;, :layout =&gt; false, :status =&gt; :see_other, :location =&gt; location)<br />
end</p>
<p>or similar.</p>
<p>This implementation more closely satisfies the spec which states a 303 SHOULD include a hypertext note with a link to the new location in the response body. Both work, it&#8217;s optional, but what the hell. If you&#8217;re going to do it anyway why not.</p>
<p>I&#8217;ve bunched my multi-flavored redirect_to_&#8230;() helpers as a module and include it in ApplicationController:</p>
<p>redirect_permanently_to(&#8230;) # =&gt; 301<br />
redirect_to_other(&#8230;) # =&gt; 303<br />
redirect_temporarily_to(&#8230;) # =&gt; 307</p>
<p>and use the stock redirect_to method for 302 redirects as written. This gets rid of the :status =&gt; ### ugliness too in the same way I use named_scope in my models.</p>
<p>Cheers</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Assaf</title>
		<link>http://labnotes.org/2007/10/23/rails-fixies-json-as-input-see-other-and-to_xml/comment-page-1/#comment-138943</link>
		<dc:creator>Assaf</dc:creator>
		<pubDate>Sat, 01 Dec 2007 03:03:54 +0000</pubDate>
		<guid isPermaLink="false">http://blog.labnotes.org/2007/10/23/rails-fixies-json-as-input-see-other-and-to_xml/#comment-138943</guid>
		<description>Gareth, using a container object requires changing all your to_json to create a container object in the response, and does weird things when your JSON request looks like this:

{ item: { ... }, _method: &#039;delete&#039; }

blweiner, I originally wanted one rendering, 303 works for both browser and programs, but perhaps it&#039;s best to separate 201 (programmable) and 303 (browser).

Neville, Ajax.Request accepts the option contentType, just set this to &#039;application/json&#039;.  But you do need to create a JSON-encoded string, which unfortunately prototype.js doesn&#039;t do for you.</description>
		<content:encoded><![CDATA[<p>Gareth, using a container object requires changing all your to_json to create a container object in the response, and does weird things when your JSON request looks like this:</p>
<p>{ item: { &#8230; }, _method: &#8216;delete&#8217; }</p>
<p>blweiner, I originally wanted one rendering, 303 works for both browser and programs, but perhaps it&#8217;s best to separate 201 (programmable) and 303 (browser).</p>
<p>Neville, Ajax.Request accepts the option contentType, just set this to &#8216;application/json&#8217;.  But you do need to create a JSON-encoded string, which unfortunately prototype.js doesn&#8217;t do for you.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Neville</title>
		<link>http://labnotes.org/2007/10/23/rails-fixies-json-as-input-see-other-and-to_xml/comment-page-1/#comment-138833</link>
		<dc:creator>Neville</dc:creator>
		<pubDate>Tue, 13 Nov 2007 00:12:52 +0000</pubDate>
		<guid isPermaLink="false">http://blog.labnotes.org/2007/10/23/rails-fixies-json-as-input-see-other-and-to_xml/#comment-138833</guid>
		<description>Hi Assaf,

I&#039;m also investigating sending JSON from the browser to my rails app, so you posting is very relevant to me. In your examples, you are using &#039;curl&#039; to contruct the request which works just fine. However, I&#039;m struggling to get prototype.js Ajax.request() to tell Rails that I&#039;m sending application/json so that Rails automagically parses the incoming JSON into params as a ruby hash.

I wonder if you might have a simple Prototype example handy which successfully sends JSON to Rails?

TIA 

Neville</description>
		<content:encoded><![CDATA[<p>Hi Assaf,</p>
<p>I&#8217;m also investigating sending JSON from the browser to my rails app, so you posting is very relevant to me. In your examples, you are using &#8216;curl&#8217; to contruct the request which works just fine. However, I&#8217;m struggling to get prototype.js Ajax.request() to tell Rails that I&#8217;m sending application/json so that Rails automagically parses the incoming JSON into params as a ruby hash.</p>
<p>I wonder if you might have a simple Prototype example handy which successfully sends JSON to Rails?</p>
<p>TIA </p>
<p>Neville</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: blweiner</title>
		<link>http://labnotes.org/2007/10/23/rails-fixies-json-as-input-see-other-and-to_xml/comment-page-1/#comment-138761</link>
		<dc:creator>blweiner</dc:creator>
		<pubDate>Mon, 29 Oct 2007 20:32:26 +0000</pubDate>
		<guid isPermaLink="false">http://blog.labnotes.org/2007/10/23/rails-fixies-json-as-input-see-other-and-to_xml/#comment-138761</guid>
		<description>It&#039;s interesting that Rails sends back 302s when you redirect; I was under the impression that 302 was informally deprecated in favor of 307. I&#039;m curious why you&#039;d want to send a 303 rather than a 201. While the 303 works--the request has succeeded, but instead of a representation here is a URI for it--it seems 201 is more appropriate. Am I missing something?

Great work on everything you&#039;ve done related to Rails. I&#039;m busy incorporating your work with conditional GET into my app.</description>
		<content:encoded><![CDATA[<p>It&#8217;s interesting that Rails sends back 302s when you redirect; I was under the impression that 302 was informally deprecated in favor of 307. I&#8217;m curious why you&#8217;d want to send a 303 rather than a 201. While the 303 works&#8211;the request has succeeded, but instead of a representation here is a URI for it&#8211;it seems 201 is more appropriate. Am I missing something?</p>
<p>Great work on everything you&#8217;ve done related to Rails. I&#8217;m busy incorporating your work with conditional GET into my app.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Gareth</title>
		<link>http://labnotes.org/2007/10/23/rails-fixies-json-as-input-see-other-and-to_xml/comment-page-1/#comment-138719</link>
		<dc:creator>Gareth</dc:creator>
		<pubDate>Thu, 25 Oct 2007 03:45:08 +0000</pubDate>
		<guid isPermaLink="false">http://blog.labnotes.org/2007/10/23/rails-fixies-json-as-input-see-other-and-to_xml/#comment-138719</guid>
		<description>What about json option 5 - use a json container so that the json object is not &quot;naked&quot; e.g.
{ item : { name : &quot;foo&quot;, count : 2, tags : [...] } }
then add the container properties directly into the params hash, so you can just use params[:item].

Using a container like this has the added benefit of leaving room for adding more information into the json response/request such as errors.</description>
		<content:encoded><![CDATA[<p>What about json option 5 &#8211; use a json container so that the json object is not &#8220;naked&#8221; e.g.<br />
{ item : { name : &#8220;foo&#8221;, count : 2, tags : [...] } }<br />
then add the container properties directly into the params hash, so you can just use params[:item].</p>
<p>Using a container like this has the added benefit of leaving room for adding more information into the json response/request such as errors.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

