Rails button_to use receive request when message is specified

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

When I first noticed this, I ran the rails server on my laptop, connected to the Internet via wireless, and I connected to it using my ipad (for testing), and the connection was pretty slow, so when the page loaded after clicking for For several seconds, the parameters were displayed in the address bar. I do not want it.

So, this prompted me to do some verification, and, as I said, under the chrome network tab a request for receipt is displayed, and in my routes, when I specify: via => :post , and then go to the page that it breaks. he does not say that the route does not match [GET] /---- . when i delete :via => :post , it works fine. this confirms that with a GET request go to the /---- page when you click button_to .

I tried specifying method = post in button_to , although the rails api says that the default message is.

Can someone give an idea of ​​why he uses "get" as opposed to "post"? I would really like him to use the post, if at all possible.

+4
source share
1 answer

I decided to remove this question in shame, but I suppose I'll just post the answer.

On my page with button_to, I had a form with some text fields. they contain semi-sensitive data that I didn’t want to sit in the URL, but I need to go to the next page. Button_to submits the specified form and redirects the corresponding page. in the form tag, I specified method=get . I just noticed it. The biggest moment of the palm this year. Thanks to everyone who read and reviewed my problem.

+1
source

Source: https://habr.com/ru/post/1440831/


All Articles