0

当用户通过 Uploadify 输入要与父上传一起提交的新文件 Uload_image 时,我正在调试我的 rails 应用程序。现在它没有保存任何记录,我目前正在调试为什么所以我在我的 upload_image 控制器的 create 方法中删除了一个 require 'debugger' 并评估了 params 哈希,这就是我得到的......

{"Filename"=>"sample.pdf", "folder"=>"/uploads/", "upload_id"=>"3", "authenticity_token"=>"gyUCME24FB4PyndTbkrzYZQkLVPtLiJQycnASK/kxbI=", "_pro-template-app-31_session"=>"BAh7CkkiD3Nlc3Npb25faWQGOgZFRkkiJTU4MTBiNzg2Mjg4OGJjNGUzMDY0ZmU0ZjJmMWJjZjFhBjsAVEkiEF9jc3JmX3Rva2VuBjsARkkiMWd5VUNNRTI0RkI0UHluZFRia3J6WVpRa0xWUHRMaUpReWNuQVNLL2t4Ykk9BjsARkkiGXdhcmRlbi51c2VyLnVzZXIua2V5BjsAVFsISSIJVXNlcgY7AEZbBmkGSSIiJDJhJDEwJHVSSXZYaDREV1p6U0tSMndtLjFRNU8GOwBUSSIOb25saW5lX2F0BjsARlU6IEFjdGl2ZVN1cHBvcnQ6OlRpbWVXaXRoWm9uZVsISXU6CVRpbWUN1REcwCCtBu8GOgtAX3pvbmVJIghVVEMGOwBUSSIfQ2VudHJhbCBUaW1lIChVUyAmIENhbmFkYSkGOwBGSXU7Bw3QERzAIK0G7wY7CEkiCFVUQwY7AFRJIgplcnJvcgY7AEZJIgAGOwBU--feba71517b823faffc30a993cc96455fa2478f71", "_method"=>"post", "format"=>"json", "_http_accept"=>"application/javascript", "Filedata"=>#<ActionDispatch::Http::UploadedFile:0x00000006af6328 @original_filename="sample.pdf", @content_type="application/octet-stream", @headers="Content-Disposition: form-data; name=\"Filedata\"; filename=\"sample.pdf\"\r\nContent-Type: application/octet-stream\r\n", @tempfile=#<File:/tmp/RackMultipart20120514-22783-xg2pm2>>, "Upload"=>"Submit Query", "action"=>"create", "controller"=>"uploads"}

我不知道从哪里开始解析 Filedata 哈希信息作为我可以实际保存的东西......也许我在我的 JS 中做错了什么?...

<script type="text/javascript" charset="utf-8">
<%- session_key = Rails.application.config.session_options[:key] -%> 
$(document).ready(function() {
    // Create an empty object to store our custom script data
    var uploadify_script_data = {};

    // Fetch the CSRF meta tag data
    var csrf_token = $('meta[name=csrf-token]').attr('content');
    var csrf_param = $('meta[name=csrf-param]').attr('content');

    // Now associate the data in the config, encoding the data safely
    uploadify_script_data[csrf_token] = encodeURI(encodeURI(csrf_param));

    // Now associate the data in the config, encoding the data safely
    uploadify_script_data[csrf_token] = encodeURI(csrf_param)


    $('.uploadify').uploadify(
    {
        uploader : '/uploadify/uploadify.swf',
        cancelImg : '/uploadify/cancel.png',
        multi : true,
        auto : true,
        script : '/uploads',
        onComplete : function(event, queueID, fileObj, response, data) 
        { 
            var dat = eval('(' + response + ')');
            $.getScript(dat.upload);
        },
        scriptData : 
        {
            '_http_accept': 'application/javascript',
            'format' : 'json',
            '_method': 'post',
            '<%= session_key %>' : encodeURIComponent('<%= u cookies[session_key] %>'),
            'authenticity_token': encodeURIComponent('<%= u form_authenticity_token %>'),
            'upload_id' : '<%= Upload.last.id + 1 %>'
          }
    });

}); 
</script>
4

1 回答 1

0

好的,就获取上传文件信息而言,答案很简单:

@new_upload_image = UploadImage.new(:image => params[:Filedata])

我还有其他并发症,但我会为此提出一个新问题。

于 2012-05-15T17:44:44.657 回答