user1759942
user1759942

Reputation: 1350

Rails button_to using get request when post is specified

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.

Upvotes: 4

Views: 531

Answers (1)

user1759942
user1759942

Reputation: 1350

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.

Upvotes: 1

Related Questions