How to Use 'Ajax Upload' with Ruby on Rails?

心不动则不痛 提交于 2019-12-06 07:32:12

问题


I'm using this Script http://valums.com/ajax-upload/ to get Ajax upload working with Ruby on Rails

but when i try uploading a file on my controller action I only get this:

Parameters: {"qqfile"=>"Foo.png"}
{"qqfile"=>"Foo.png", "action"=>"ul_file", "controller"=>"upload_files"}

but i cant use this as a file and do things as

thefile = params[:qqfile]

foo = thefile.original_filename.slice(thefile.original_filename.rindex("."), thefile.original_filename.length).downcase

what do i need to do to get this script working with Ruby on Rails?

Thanks.

///////// Updated

This is how the JS looks Like



$(document).ready(function(){
    var uploader = new qq.FileUploader({
        // pass the dom node (ex. $(selector)[0] for jQuery users)
        element: $('#file-uploader')[0],
        // path to server-side upload script
        action: '/NzzT/upload_files/ul_file'
    });

});



回答1:


my solution posted in this comment

I write QqFile for easy uploader. With paperclip example




回答2:


Here's a good solution using CarrierWave:

https://github.com/jnicklas/carrierwave/wiki/How-to%3A-Upload-from-a-string-in-Rails-3 https://groups.google.com/forum/#!topic/carrierwave/KBn2WmrwRAs

The syntax looks like this and works like a charm:

file = CarrierwaveStringIO.new(params[:qqfile], request.raw_post)


来源:https://stackoverflow.com/questions/5411957/how-to-use-ajax-upload-with-ruby-on-rails

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!