# POST vs GET

**URL:** <https://www.ruby-forum.com/t/post-vs-get/94754>\
**Category:** Rails\
**Created:** [May 13, 2006, 12:15am UTC](https://www.ruby-forum.com/t/post-vs-get/94754 "2006-05-13T00:15:10Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ben\_Nevile](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/48db29/32.png) [@Ben\_Nevile](https://www.ruby-forum.com/u/Ben_Nevile)\
**Post date:** [May 13, 2006, 12:15am UTC](https://www.ruby-forum.com/t/post-vs-get/94754/1 "2006-05-13T00:15:10Z")

</div>

I read in the Agile Rails book that I should avoid GETs for  
destructive actions. I notice that on 37signals’ Backpack web site,  
deleting an item in a list is accomplished with a simple click on a  
picture of a trash can. Is this a violation of the POST/GET rule  
noted above, or is there some way to make a clickable link send a  
POST?

Ben

---

<div class="post-metadata">

**Author:** ![Ben\_Nevile](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/48db29/32.png) [@Ben\_Nevile](https://www.ruby-forum.com/u/Ben_Nevile)\
**Post date:** [May 13, 2006, 12:24am UTC](https://www.ruby-forum.com/t/post-vs-get/94754/2 "2006-05-13T00:24:35Z")

</div>

## Hi, Here is a quote from DHH. You can find it here: [The Google Web Accelerator is back with a vengeance - Signal vs. Noise (by 37signals)](http://www.37signals.com/svn/archives2/the_google_web_accelerator_is_back_with_a_vengeance.php)

If you?re using Rails, you can now do links like: link\_to ?Destroy!?,  
:action =\> ?destroy?, :post =\> true. That?ll create a link with an  
onclick that uses POST for submit. If the user has js turned off, a GET  
will still be send. On the server-side, you can then use verify  
:destroy, :method =\> :post.  
Yeah, it?s a bit cumbersome, but at least it?s there.

* * *

-Eric G.  
[ericgoodwin.com](http://ericgoodwin.com)

Ben Nevile wrote:

> removed\_email\_address@domain.invalid  
> [http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)

–  
Eric G.  
[http://www.ericgoodwin.com](http://www.ericgoodwin.com)

---

<div class="post-metadata">

**Author:** ![Ben\_Nevile](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/48db29/32.png) [@Ben\_Nevile](https://www.ruby-forum.com/u/Ben_Nevile)\
**Post date:** [May 13, 2006, 2:15am UTC](https://www.ruby-forum.com/t/post-vs-get/94754/3 "2006-05-13T02:15:26Z")

</div>

Thanks for your response, Eric. If I may be permitted a follow-up  
question,

> On the server-side, you can then use verify  
> :destroy, :method =\> :post.

Am I correct in assuming that this call should be in my  
ApplicationController class? It’s the only controller in my app  
that’s a direct subclass of ActionColler::Base.

if I add

verify :remove\_from\_chosen\_labels, :method =\> :post

rails complains that I have the wrong number of arguments (it expects  
one.) the call

verify :only =\> :remove\_from\_chosen\_labels, :method =\> :post

sends me to a blank page, even though through the method you describe  
above I have set post = TRUE (and this is verified in the URL of this  
blank page.) if I say

verify :only =\> :remove\_from\_chosen\_labels, :method =\> :post,  
:redirect\_to :index

I get a stack overflow.

Any hints for this newbie?

Thanks everyone,  
Ben

---

<div class="post-metadata">

**Author:** ![Ben\_Nevile](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/48db29/32.png) [@Ben\_Nevile](https://www.ruby-forum.com/u/Ben_Nevile)\
**Post date:** [May 13, 2006, 2:30am UTC](https://www.ruby-forum.com/t/post-vs-get/94754/4 "2006-05-13T02:30:55Z")

</div>

|Hi Ben,

This should work.

class WhateverController \< ActionController::Base  
| verify :method =\> :post, :only =\> :remove\_from\_chosen\_labels, :redirect\_to =\> { :action=\> “index” }  
|  
def |remove\_from\_chosen\_labels  
| # a GET request will never gain access to me  
end  
end

I’ve taken it from Loud Thinking and modified it a bit. If you check out  
the post there is some more info on it.  
[http://www.loudthinking.com/arc/000529.html](http://www.loudthinking.com/arc/000529.html)

If you are using route names and have and index url specified then you  
can should be able to just have:  
|:redirect\_to =\> :index\_url

I’ve included a few comments in your post below as well.

Cheers,  
Eric G.  
|  
|

Ben Nevile wrote:

> if I add
> 
> verify :remove\_from\_chosen\_labels, :method =\> :post  
> You’re passing in a hash, you need to specify the key and the value. ie  
> key =\> value  
> This method can be rewritten as:  
> verify({:method =\> :post,:only =\>:remove\_from\_chosen\_labels })
> 
> rails complains that I have the wrong number of arguments (it expects  
> one.) the call
> 
> verify :only =\> :remove\_from\_chosen\_labels, :method =\> :post  
> hmmm … not sure why this isn’t working
> 
> sends me to a blank page, even though through the method you describe  
> above I have set post = TRUE (and this is verified in the URL of this  
> blank page.) if I say
> 
> verify :only =\> :remove\_from\_chosen\_labels, :method =\> :post,  
> :redirect\_to :index  
> missing ‘=\>’  
> [http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)  
> –  
> Eric G.  
> [http://www.ericgoodwin.com](http://www.ericgoodwin.com)

---

<div class="post-metadata">

**Author:** ![Ben\_Nevile](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/48db29/32.png) [@Ben\_Nevile](https://www.ruby-forum.com/u/Ben_Nevile)\
**Post date:** [May 13, 2006, 2:21am UTC](https://www.ruby-forum.com/t/post-vs-get/94754/5 "2006-05-13T02:21:38Z")

</div>

To answer my own question,

the problem was that I actually was not generating POSTs. This is  
because I had

\<%= link\_to “#{@chosen\_labels[i].name}”, :action =\>  
‘remove\_from\_chosen\_labels’, :id =\> @chosen\_labels[i].id, :post =\>  
true %\>

but I should have had

\<%= link\_to “#{@chosen\_labels[i].name}”, {:action =\>  
‘remove\_from\_chosen\_labels’, :id =\> @chosen\_labels[i].id}, :post =\>  
true %\>

Ben
