简体   繁体   English

我如何在Ruby on Rails中使用post方法

[英]How I use post method in Ruby on Rails

when I submit one page to another, the sites shows the information! 当我将一页提交到另一页时,站点将显示信息! Someone told me to use post to avoid it. 有人告诉我使用帖子来避免它。 however, when I use post method it doesn't work. 但是,当我使用post方法时,它不起作用。

<form action="\look\at", method="post">
Select your new car's color.
<br>
<input type="radio" name="radios1" value="red">red
<input type="radio" name="radios1" value="green">green
<input type="radio" name="radios1" value="blue">blue
<br>
<br>
<input type="submit"/>
</form>

When I submit I can not see \\look\\at page. 我提交时看不到\\look\\at页面。 but I delete method="post" It works well. 但我删除method="post"效果很好。 How I use post method? 我如何使用邮政方式?

Check your routes (in config/routes.rb ). 检查您的路由(在config/routes.rb )。

Probably you will have a line 可能你会排队

get '/look/at', to: 'look#at'

replace get by post and it will accept a post. 替换通过post get ,它将接受一个邮寄。

Since you are not using the rails form helper or view mechanism (erb/haml) (please start using them, why write plain html????), you have to skip the authenticity token check (please note that this check is there for a reason: it is a protection against cross-site request forgery). 由于您未使用Rails表单帮助程序或视图机制(erb / haml)(请开始使用它们,为什么要编写纯html ????),因此您必须跳过真实性令牌检查(请注意,此检查用于原因:这是对跨站点请求伪造的保护)。

Just add the following line at the top of your controller: 只需在控制器顶部添加以下行:

 skip_before_filter :verify_authenticity_token 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM