我只是从一些用户那里获得了InvalidAuthenticityToken异常。当我检查错误时,我可以看到请求已将"\r\n"
添加到authenticity_token参数(即:"authenticity_token"=>"YfYr7bzy1MFzNHPvrSOIdrYuuAG3SHZy/OBJyV3yUSg=\r\n"
)。
除了它是IE7之外,我对浏览器一无所知。
我感觉他们的防火墙正在为请求做些什么。我认为一个聪明的解决方案是创建一个Rack中间件,如果它们存在则删除换行符。谁能告诉我怎么做? (我没有Rack经验)。
问候,
雅各
答案 0 :(得分:1)
我已经调查过,我找不到解决方法。它不是IE或IE7。我最终制作了以下中间件:
class AuthenticityTokenFix
def initialize(app)
@app=app
end
def call(env)
if env["rack.request.form_hash"] && env["rack.request.form_hash"]["authenticity_token"]
env["rack.request.form_hash"]["authenticity_token"]=env["rack.request.form_hash"]["authenticity_token"].gsub("\r\n",'')
end
@app.call(env)
end
end
解决了这个问题。