Rails 3 swf_upload InvalidAuthenticityToken 和发送 cookie 会话
我有一个 swfupload 在 Rails 3 上使用回形针(终于!) 我在控制器中使用以下行关闭了 autehnticitytoken:
skip_before_filter :verify_authenticity_token, :only => :create
我知道正在尝试让会话正常工作(闪存不会发送此信息) 当然,我用谷歌搜索了我的屁股,但到目前为止还没有运气。 这就是我的看法(部分)
'<%= u session_key_name %>' : encodeURIComponent('<%= u cookies[session_key_name] %>'),
'authenticity_token' : '<%= form_authenticity_token %>',
'gallerie_id' : '<%= params[:gallery_id] %>'
所以我将会话密钥与发布数据一起发送。我必须用一些中间件代码“捕获”这些参数。
require 'rack/utils'
class FlashSessionCookieMiddleware
def initialize(app, session_key = '_session_id')
@app = app
@session_key = session_key
end
def call(env)
if env['HTTP_USER_AGENT'] =~ /^(Adobe|Shockwave) Flash/
req = Rack::Request.new(env)
env['HTTP_COOKIE'] = [ @session_key,
req.params[@session_key] ]
.join('=').freeze unless req.params[@session_key].nil?
env['HTTP_ACCEPT'] = "#{req.params['_http_accept']}"
.freeze unless req.params['_http_accept'].nil?
end
@app.call(env)
end
end
谁能帮助我!现在真的卡住了!
I have a swfupload working with paperclip on rails 3 (finally!)
I turned off the autehnticitytoken with the following line in my controller:
skip_before_filter :verify_authenticity_token, :only => :create
I know am trying to get sessions working (flash doesn't send this)
Of course i googled my ass of but no luck so far.
this is what i have in my view (part of it)
'<%= u session_key_name %>' : encodeURIComponent('<%= u cookies[session_key_name] %>'),
'authenticity_token' : '<%= form_authenticity_token %>',
'gallerie_id' : '<%= params[:gallery_id] %>'
So i send the session key with the post data. I have to "catch" those params with some middleware code.
require 'rack/utils'
class FlashSessionCookieMiddleware
def initialize(app, session_key = '_session_id')
@app = app
@session_key = session_key
end
def call(env)
if env['HTTP_USER_AGENT'] =~ /^(Adobe|Shockwave) Flash/
req = Rack::Request.new(env)
env['HTTP_COOKIE'] = [ @session_key,
req.params[@session_key] ]
.join('=').freeze unless req.params[@session_key].nil?
env['HTTP_ACCEPT'] = "#{req.params['_http_accept']}"
.freeze unless req.params['_http_accept'].nil?
end
@app.call(env)
end
end
can anybody help me! really stuck now!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这可能是因为“session_key”更改为“key”。以下是对我有用的更新。
另外,在设置 javascript 变量时,您需要检查以确保您的 javascript 在
ActionController::Base.session_options[:key]
中使用的是“key”而不是“session_key”。It's probably because "session_key" changed to just "key". Below is this update that works for me.
Also, you'll want to check to make sure your javascript is using the "key" instead of "session_key" for
ActionController::Base.session_options[:key]
when setting your javascript variable.