我试图让http://www.uploadify.com/使用Ruby on Rails 3.0.3,文件正在上传但是我试图修复以下错误消息。任何帮助非常感谢。
在2011-02-10 16:57:16 +0000开始发布“/ videos /”for 10.170.163.142 由VideosController处理#create as HTML 参数:{ “文件名”=> “中tvshow.avi”, “文件夹”=> “中/”, “_website_session”=> “中BAh7CEkiD3Nlc3Npb25faWQGOgZFRiIlOTA1OTIwODE1NDNkZDhkYzU2Yjc0MWJhMTdiNWFlZTlJIhBfY3NyZl90b2tlbgY7AEZJIjEvd3dnSjQ3NE83cDQ3SkF0ZXU4alN3dHdkaHl5Wm9vV29XRllBOWc1ajRBPQY7AEZJIgx1c2VyX2lkBjsARmkG - f618cf0d51fe1beebcc03eb200d1b3d023c98757”, “/ wwgJ474O7p47JAteu8jSwtwdhyyZooWoWFYA9g5j4A”=> “中= authenticity_token”, “Filedata”=>#>,“上传”=>“提交查询”} 在0ms完成
ActionController :: InvalidAuthenticityToken(ActionController :: InvalidAuthenticityToken): app / middleware / flash_session_cookie_middleware.rb:17:在`call'
Rendered /Volumes/Storage/.rvm/gems/ruby-1.9.2-p136/gems/actionpack-3.0.3/lib/action_dispatch/middleware/templates/rescues/_trace.erb(2.8ms) Rendered /Volumes/Storage/.rvm/gems/ruby-1.9.2-p136/gems/actionpack-3.0.3/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb(11.2ms) 在救援/布局(20.4ms)内呈现/Volumes/Storage/.rvm/gems/ruby-1.9.2-p136/gems/actionpack-3.0.3/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb
我不明白这里发生了什么,为什么文件不上传?
require 'rack/utils'
class FlashSessionCookieMiddleware
include Rack::Utils
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/
params = ::Rack::Request.new(env).params
env['HTTP_COOKIE'] = [ @session_key, params[@session_key] ].join('=').freeze unless params[@session_key].nil?
end
@app.call(env)
end
end
答案 0 :(得分:1)
我发现这个插件https://github.com/trevorturk/flash_cookie_session做得很好,这是我的观点
<% content_for :head do %>
<link href="/uploadify/uploadify.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="/uploadify/jquery.min.js"></script>
<script type="text/javascript" src="/uploadify/swfobject.js"></script>
<script type="text/javascript" src="/uploadify/jquery.uploadify.min.js"></script>
<script type="text/javascript">
<%- session_key = Rails.application.config.session_options[:key] -%>
$(document).ready(function() {
$('#video-upload').uploadify({
uploader : '/uploadify/uploadify.swf',
cancelImg : '/uploadify/cancel.png',
auto : true,
multi : false,
script : '/videos/',
onComplete : function(a, b, c, response){ eval(response) },
scriptData : {
"<%= key = Rails.application.config.session_options[:key] %>" : "<%= cookies[key] %>",
"<%= request_forgery_protection_token %>" : "<%= form_authenticity_token %>",
}
});
});
</script>
<% end %>
谢谢大家。
答案 1 :(得分:1)
我已经浏览了一段时间,终于找到了这个代码使用。但是,有更新的Uploadify选项。快速c / p(这是HAML)
Uploadify 3.1
$(document).ready(function() {
$('#image-uploader').uploadify({
swf : '/uploadify/uploadify.swf',
uploadLimit : 10,
auto : true,
multi : false,
script : '/videos/',
onComplete : function(a, b, c, response){ eval(response) },
formData : {
'"#{key = Rails.application.config.session_options[:key]}"' : '"#{cookies[key]}"',
'#{request_forgery_protection_token}' : '#{form_authenticity_token}',
}
});
});
这部分:
cancelImg : '/images/uploadify/cancel.png',
已移至CSS档案。
对于会话,使用flash_cookie_session gem,它比试图解决方案要好得多。
答案 2 :(得分:0)
我建议您在初始化中打印@session_key,并确保它是正确的。密钥的名称及其值必须与初始化程序中的名称相同。
答案 3 :(得分:0)
只需注意,在rails 3上我必须添加u和encodeURIComponent以使其正常工作。
{
"<%= key = Rails.application.config.session_options[:key] %>" : "<%= u cookies[key] %>",
"<%= request_forgery_protection_token %>" : encodeURIComponent("<%= u form_authenticity_token %>"),
}