gpt4 book ai didi

ruby-on-rails - Uploadify 和 rails 3 真实性 token

转载 作者:行者123 更新时间:2023-12-04 06:26:40 26 4
gpt4 key购买 nike

我正在尝试使用 uploadify ( http://www.uploadify.com ) 在 rails 3 应用程序中获取文件上传进度条,但我被困在真实性 token 上。我当前的uploadify配置看起来像

            <script type="text/javascript" charset="utf-8">
$(document).ready(function() {
$("#zip_input").uploadify({
'uploader': '/flash/uploadify.swf',
'script': $("#upload").attr('action'),
'scriptData': { 'format': 'json', 'authenticity_token': encodeURIComponent('<%= form_authenticity_token if protect_against_forgery? %>') },
'fileDataName': "world[zip]",
//'scriptAccess': 'always', // Incomment this, if for some reason it doesn't work
'auto': true,
'fileDesc': 'Zip files only',
'fileExt': '*.zip',
'width': 120,
'height': 24,
'cancelImg': '/images/cancel.png',
'onComplete': function(event, data) { $.getScript(location.href) }, // We assume that we can refresh the list by doing a js get on the current page
'displayData': 'speed'
});
});
</script>

但我从 rails 得到这个回应:
Started POST "/worlds" for 127.0.0.1 at 2010-04-22 12:39:44

ActionController::InvalidAuthenticityToken (ActionController::InvalidAuthenticityToken):


Rendered /opt/local/lib/ruby/gems/1.8/gems/actionpack-3.0.0.beta3/lib/action_dispatch/middleware/templates/rescues/_trace.erb (1.0ms)
Rendered /opt/local/lib/ruby/gems/1.8/gems/actionpack-3.0.0.beta3/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (6.6ms)
Rendered /opt/local/lib/ruby/gems/1.8/gems/actionpack-3.0.0.beta3/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb within rescues/layout (12.2ms)

这似乎是因为我没有将身份验证 cookie 与请求一起发送。有谁知道我如何获得应该发送到那里的值,以及如何让 rails 从 HTTP POST 读取它而不是试图将它作为 cookie 来查找?

最佳答案

这似乎是 rails 3 的错误。

https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/3913

这意味着我必须改变我跳过真实性 token 检查的方式:

改自

protect_from_forgery :except => :upload


skip_before_filter :verify_authenticity_token, :only => :upload

这似乎仍然可以正常工作

关于ruby-on-rails - Uploadify 和 rails 3 真实性 token ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2690450/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com