Skip to content

Commit

Permalink
Merge commit 'akahn/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
rtomayko committed Jan 29, 2010
2 parents 51e3ac9 + 5d92783 commit f73b265
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
10 changes: 9 additions & 1 deletion _includes/book.html
Expand Up @@ -212,13 +212,21 @@ <h2 id='other_methods'>Other methods</h2>

<h2 id='the_put_and_delete_methods'>The PUT and DELETE methods</h2>

<p>Since browsers don&#8217;t natively support the PUT and DELETE methods, a hacky workaround has been adopted by the web community. Simply add a hidden element with the name &#8220;_method&#8221; and the value equal to the HTTP method you want to use. The form itself is sent as a POST, but Sinatra will interpret it as the desired method. For example:</p>
<p>Since browsers don&#8217;t natively support the PUT and DELETE methods, a hacky workaround has been adopted by the web community. Simply add a hidden element with the name &#8220;_method&#8221; and the value equal to the HTTP method you want to use. Although the form itself is sent as a POST, Sinatra will interpret the request as the desired method. For example, this form:</p>

<pre><code>&lt;form method=&quot;post&quot; action=&quot;/destroy_it&quot;&gt;
&lt;input name=&quot;_method&quot; value=&quot;delete&quot; /&gt;
&lt;div&gt;&lt;button type=&quot;submit&quot;&gt;Destroy it&lt;/button&gt;&lt;/div&gt;
&lt;/form&gt;</code></pre>

<p>Will trigger the following route:</p>

<pre><code>delete '/destroy_it' do
# Your code
end</code></pre>

<p>Note that subclassed Sinatra apps will need to enable this functionality with the line <code>enable :methodoverride</code>.</p>

<p>When you want to use PUT or DELETE from a client that does support them (like Curl, or ActiveResource), just go ahead and use them as you normally would, and ignore the <code>_method</code> advice above. That is only for hacking in support for browsers.</p>

<h2 id='how_routes_are_looked_up'>How routes are looked up</h2>
Expand Down
4 changes: 2 additions & 2 deletions faq.markdown
Expand Up @@ -298,10 +298,10 @@ II. When you want to protect only certain URLs in the application, or want the a
helpers do

def protected!
unless authorized?
unless authorized?
response['WWW-Authenticate'] = %(Basic realm="Testing HTTP Auth")
throw(:halt, [401, "Not authorized\n"])
end
end
end

def authorized?
Expand Down

0 comments on commit f73b265

Please sign in to comment.