# HTTP Post request for a link

**URL:** <https://www.ruby-forum.com/t/http-post-request-for-a-link/142714>\
**Category:** Rails\
**Created:** [July 10, 2008, 7:38pm UTC](https://www.ruby-forum.com/t/http-post-request-for-a-link/142714 "2008-07-10T19:38:08Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![jturney](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e99b99/32.png) [@jturney](https://www.ruby-forum.com/u/jturney)\
**Post date:** [July 10, 2008, 7:38pm UTC](https://www.ruby-forum.com/t/http-post-request-for-a-link/142714/1 "2008-07-10T19:38:08Z")

</div>

\<%= link\_to image\_tag(product.url), :action =\> :add\_to\_cart, :method =\>  
:delete, :id =\> product %\>

Hi,

Did I implement this link correctly to send an HTTP Post request?

Thanks

---

<div class="post-metadata">

**Author:** ![jturney](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e99b99/32.png) [@jturney](https://www.ruby-forum.com/u/jturney)\
**Post date:** [July 10, 2008, 8:19pm UTC](https://www.ruby-forum.com/t/http-post-request-for-a-link/142714/2 "2008-07-10T20:19:40Z")

</div>

Looks good if you want the http protocol to be delete… I think what  
you want is :method =\> :post

:method =\> symbol of HTTP verb - This modifier will dynamically create  
an HTML form and immediately submit the form for processing using the  
HTTP verb specified. Useful for having links perform a POST operation  
in dangerous actions like deleting a record (which search bots can  
follow while spidering your site). Supported verbs are :post, :delete  
and :put. Note that if the user has JavaScript disabled, the request  
will fall back to using GET. If you are relying on the POST behavior,  
you should check for it in your controller‘s action by using the  
request object‘s methods for post?, delete? or put?.

---

<div class="post-metadata">

**Author:** ![jturney](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e99b99/32.png) [@jturney](https://www.ruby-forum.com/u/jturney)\
**Post date:** [July 10, 2008, 11:19pm UTC](https://www.ruby-forum.com/t/http-post-request-for-a-link/142714/3 "2008-07-10T23:19:38Z")

</div>

> If you are relying on the POST behavior,  
> you should check for it in your controllerï¿½s action by using the  
> request objectï¿½s methods for post?, delete? or put?.

I don’t understand that =) Can you explain in more detail please

---

<div class="post-metadata">

**Author:** ![jturney](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e99b99/32.png) [@jturney](https://www.ruby-forum.com/u/jturney)\
**Post date:** [July 10, 2008, 11:23pm UTC](https://www.ruby-forum.com/t/http-post-request-for-a-link/142714/4 "2008-07-10T23:23:34Z")

</div>

Also, I’m trying to use sessions in my database…but after I did rake  
db:sessions:create, rake db:migrate, I got this error:

ActionController::InvalidAuthenticityToken in Store#index

Showing store/index.html.erb where line #9 raised:

No :secret given to the #protect\_from\_forgery call. Set that or use a  
session store capable of generating its own keys (Cookie Session Store).

Extracted source (around line #9):

6:

### \<%=h product.title %\>
  
7: \<%= product.description %\>  
  
8: \<%= number\_to\_currency(product.price)  
%\>  
9: \<%= button\_to(“Add to Cart”, :action =\> :add\_to\_cart, :id =\>  
product) %\>  
10:   
   
   
  
11:   
12: \<% end %\>

Thanks for the help!

---

<div class="post-metadata">

**Author:** ![jturney](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e99b99/32.png) [@jturney](https://www.ruby-forum.com/u/jturney)\
**Post date:** [July 11, 2008, 4:53am UTC](https://www.ruby-forum.com/t/http-post-request-for-a-link/142714/5 "2008-07-11T04:53:59Z")

</div>

Hi Justin,

Justin To wrote:

> Also, I’m trying to use sessions in my database…but after I did  
> rake db:sessions:create, rake db:migrate, I got this error:
> 
> ActionController::InvalidAuthenticityToken in Store#index
> 
> Showing store/index.html.erb where line #9 raised:
> 
> No :secret given to the #protect\_from\_forgery call. Set that or use a  
> session store capable of generating its own keys (Cookie Session Store).

Did you change the settin in environment.rb?

HTH,  
Bill

---

<div class="post-metadata">

**Author:** ![jturney](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e99b99/32.png) [@jturney](https://www.ruby-forum.com/u/jturney)\
**Post date:** [July 11, 2008, 5:37am UTC](https://www.ruby-forum.com/t/http-post-request-for-a-link/142714/6 "2008-07-11T05:37:46Z")

</div>

I figured it out: named the file wrong. I’m new, so I’m unfamiliar with  
the rails conventions.

Thanks
