rail autocomplete

具体就是参考这篇文章:

http://ajax.howtosetup.info/savor-the-scriptaculous/create-an-auto-complete-field/

但是我复制代码发现没有效果,抓包看日志的结果是HTTP422错误(但是GET请求没有问题,POST请求需要带token key?):
ActionController::InvalidAuthenticityToken (ActionController::InvalidAuthenticityToken):
/vendor/rails/actionpack/lib/action_controller/request_forgery_protection.rb:86:in verify_authenticity_token'
/vendor/rails/activesupport/lib/active_support/callbacks.rb:173:in
send’
……

google了一下,在相应的controller中添加这句话:
protect_from_forgery :only => [:create, :update, :destroy]

这样即可。

Leave a Comment

Your email address will not be published. Required fields are marked *