<?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#"
	>

<channel>
	<title>Rails - Cognizant Transmutation</title>
	<atom:link href="https://www.ibd.com/tag/rails/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.ibd.com</link>
	<description>Internet Bandwidth Development: Composting the Internet for over Two Decades</description>
	<lastBuildDate>Fri, 16 Jan 2009 07:32:10 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.1</generator>

<image>
	<url>https://i0.wp.com/www.ibd.com/wp-content/uploads/2019/01/fullsizeoutput_7ae8.jpeg?fit=32%2C32&#038;ssl=1</url>
	<title>Rails - Cognizant Transmutation</title>
	<link>https://www.ibd.com</link>
	<width>32</width>
	<height>32</height>
</image> 
<atom:link rel="hub" href="https://pubsubhubbub.appspot.com"/><atom:link rel="hub" href="https://pubsubhubbub.superfeedr.com"/><atom:link rel="hub" href="https://websubhub.com/hub"/><site xmlns="com-wordpress:feed-additions:1">156814061</site>	<item>
		<title>Cross Domain RESTful AJAX with jQuery and Rails 2.2.2</title>
		<link>https://www.ibd.com/howto/cross-domain-restful-ajax-with-jquery-and-rails-222/</link>
					<comments>https://www.ibd.com/howto/cross-domain-restful-ajax-with-jquery-and-rails-222/#comments</comments>
		
		<dc:creator><![CDATA[Robert J Berger]]></dc:creator>
		<pubDate>Fri, 16 Jan 2009 07:32:10 +0000</pubDate>
				<category><![CDATA[HowTo]]></category>
		<category><![CDATA[Ruby / Rails]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[monkey patch]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[ubuntu]]></category>
		<guid isPermaLink="false">http://blog2.ibd.com/?p=156</guid>

					<description><![CDATA[<p>Flinn Mueller aka actsasflinn wrote an blog post Cross domain RESTful JSON-P with Rails back in July. There he showed how to monkeypatch Rails to allow json-p to do all the REST verbs even when going across domains. He also showed how to make the json-p calls with jquery. A very nice solution that we take advantage of in one&#8230;</p>
<p>The post <a href="https://www.ibd.com/howto/cross-domain-restful-ajax-with-jquery-and-rails-222/">Cross Domain RESTful AJAX with jQuery and Rails 2.2.2</a> first appeared on <a href="https://www.ibd.com">Cognizant Transmutation</a>.</p>]]></description>
										<content:encoded><![CDATA[<p><a href="http://www.actsasflinn.com" target="_blank">Flinn Mueller aka actsasflinn</a> wrote an blog post <a href="http://www.actsasflinn.com/2008/06/13/cross-domain-restful-json-p-with-rails" target="_blank">Cross domain RESTful JSON-P with Rails</a> back in July. There he showed how to monkeypatch Rails to allow json-p to do all the REST verbs even when going across domains. He also showed how to make the json-p calls with jquery. A very nice solution that we take advantage of in one of our apps. The only problem we had was that it stopped working when we upgraded to Rails 2.2.2.</p>
<p>There are other issues using this technique. To quote Flinn:</p>
<blockquote><p>Achtung! Monkey patching with the above will expose your create method without using an actual post. Imho no big deal, others might be more cautious (<a href="http://actsasflinn.com/articles/2008/04/27/captcha-sucks">CAPTCHA</a>is always an option), ymmv.</p></blockquote>
<p>See his original article for details on how to use it generally. </p>
<p>The problem with the monkeypatch that he wrote up is that Rails 2.2.2 changed the function that was monkeypatched so the patch stopped working. Below is code that will work on both pre and post 2.2.2 Rails:</p>
<pre>
<pre>
<span>module</span> ActionController
<span>  class</span> AbstractRequest

<span>    </span><span>def</span> request_method

<span>      if</span> Rails::VERSION::STRING &lt;<span> "2.2.2"</span>

<span>        <span>@request_method</span><span> ||=</span><span> begin</span></span>

<span>          method = (parameters[<span>:_method</span>].blank? ?<span> </span><span>@env</span>[<span>'REQUEST_METHOD'</span>] : parameters[<span>:_method</span>].to_s).<span>downcase</span></span>

<span><span>          if</span> ACCEPTED_HTTP_METHODS.include?(method)</span>

            method.to_sym

          else

            raise UnknownHttpMethod,<span> "#{</span>method<span>}, accepted HTTP methods are #{</span>ACCEPTED_HTTP_METHODS.to_a.to_sentence<span>}"</span>

<span>          end</span>

        end

      else

        method =<span> </span><span>@env</span>[<span>'REQUEST_METHOD'</span>]

        method = parameters[<span>:_method</span>]<span> unless</span> parameters[<span>:_method</span>].blank?

        HTTP_METHOD_LOOKUP[method] || raise(UnknownHttpMethod,<span> "#{</span>method<span>}, accepted HTTP methods are #{</span>HTTP_METHODS.to_sentence<span>}"</span>)
      end

    end

  end
end</pre><p>The post <a href="https://www.ibd.com/howto/cross-domain-restful-ajax-with-jquery-and-rails-222/">Cross Domain RESTful AJAX with jQuery and Rails 2.2.2</a> first appeared on <a href="https://www.ibd.com">Cognizant Transmutation</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://www.ibd.com/howto/cross-domain-restful-ajax-with-jquery-and-rails-222/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">156</post-id>	</item>
	</channel>
</rss>
