4

So in my rails application I have a button_to on one of my pages. When I click that button on the page, it goes to the appropriate action and does everything I want, BUT: It uses a GET request. When I look in the chrome console under network it shows it using a GET request.

When I first noticed this I was running the rails server on my laptop connected to internet via wireless and I was connecting to that using my ipad (for testing purposes) and the connection was rather slow so when the page loaded after clicking the button the parameters were displayed in the address bar for a few seconds. I DO NOT want this.

So, that prompted me to do some checking and as I say, under the chrome network tab it shows a get request, and in my routes when I specify : via => :post and then go to the page it breaks. it says no route matches [GET] /----. when I remove the :via => :post it works fine. this confirms it is using a GET request to go to the /---- page when clicking on the button_to.

I have tried specifying method = post in the button_to although rails api says it defaults to a post.

Can anyone offer some insight into why it uses 'get' as opposed to 'post'? I would very much prefer it uses post if at all possible.

gnat
  • 6,213
  • 108
  • 53
  • 73
user1759942
  • 1,322
  • 4
  • 14
  • 33
  • 1
    is this button part of a form? the action method is specified as part of the form, not the button itself. – Doon Oct 19 '12 at 16:44
  • I actually didn't notice your comment untill after I noticed and fixed my mistake. But you hit the nail on the head sir and for that I thank you because I would eventually have seen your comment if I hadnt found the answer anyways. – user1759942 Oct 19 '12 at 17:20

1 Answers1

1

I considered deleting this question in shame but I figure I'll just post the answer.

On my page with the button_to I had a form with some textfields. these contain semi sensitive data that I did not want sitting in the url but that I do need to pass to the next page. The button_to submits said form and redirects to the appropriate page. in the form tag I specified method=get. I just noticed that. Biggest face palm moment of this year. thanks to anyone the read and considered my problem.

user1759942
  • 1,322
  • 4
  • 14
  • 33
  • +1 for coming back with a solution as it may help someone. (Was a different problem to the one I was searching for but still.) – ootoovak Jul 31 '13 at 04:57