rails firefox ActionController::InvalidAuthenticityToken

 
写了个简单的应用(不过是早期阶段

在提交表格到数据库的时候
出现 ActionController::InvalidAuthenticityToken 该错误
GOOGLE 之

原来是rails 防御跨站点攻击检测导致的(还特别是firefox有问题 IE正常...

http://api.rubyonrails.org/classes/ActionController/RequestForgeryProtection/ClassMethods.html#M000693

找到上述官方文档

一种解决办法是
整个关闭

在environment.rb中添加
config.action_controller.allow_forgery_protection = false
还有就是到controller 排除
以下是官方给的example

class FooController < ApplicationController

# uses the cookie session store (then you don't need a separate :secret)
protect_from_forgery :except => :index
# uses one of the other session stores that uses a session_id value.
protect_from_forgery :secret => 'my-little-pony', :except => :index
# you can disable csrf protection on controller-by-controller basis:
skip_before_filter :verify_authenticity_token
end
我的情况是create 这action 出错
直接 protect_from_forgery :exception => :create 搞定
这下正常了
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值