Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

making POST request in rails with hyperlinks

I need a bunch of links on a page each of which makes a POST to a different controller. But when I use normal links, I get a ActionController::InvalidAuthenticityToken error. I understand this is because of the missing authenticity_token value. But I don't want to use forms to do the POST because I want them to be links and not buttons. Fact is, I want complete control over the styling of the links and buttons just don't do it for me. What's the standard way of doing such things?

like image 554
akula1001 Avatar asked Aug 15 '10 02:08

akula1001


1 Answers

You have lots of options.

  1. Disable AT check: protect_from_forgery :only => []
  2. Assign onclick handler to the link and submit hidden form with javascript.
  3. Grab AT while generating view and add it as request parameter.

BTW, how exactly do you make 'post' requests using only 'href' attribute? I thought form is a must for that.

like image 132
Nikita Rybak Avatar answered Oct 14 '22 18:10

Nikita Rybak