我们正在将Rails 3.0.0迁移到Rails 3.2.21。突然,我们开始在集成测试中体验InvalidAuthenticityToken,用户在那里注册(见下文)。
post_via_redirect login_url, {:login => { :login => @user.login, :password => @user.password }
我们有自定义的身份验证逻辑,而且它在更早的时候运行得很好。
我们还尝试在上面的调用中手动传递authenticity_token,但没有帮助。我们尝试调试并发现,当我们传递authenticity_token(使用SecureRandom.base64(32))时,_csrf_token值与我们在authenticity_token中传递的值不匹配。
我们缺少任何配置了吗?
发布于 2015-02-09 06:00:50
为authenticity_token定义一个方法,并在任何地方使用该错误。
def set_form_authenticity_token
session[:_csrf_token] ||= SecureRandom.base64(32)
end例如。params.merge(authenticity_token: set_form_authenticity_token)
https://stackoverflow.com/questions/27293013
复制相似问题