简体   繁体   中英

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.

<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. but I delete method="post" It works well. How I use post method?

Check your routes (in 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.

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).

Just add the following line at the top of your controller:

 skip_before_filter :verify_authenticity_token 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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