如何在Ruby on Rails中使用“Ajax上传”?
我正在使用这个脚本http://valums.com/ajax-upload/来使用Ruby on Rails进行Ajax上传
但是当我尝试在我的控制器动作上传文件时,我只能得到这个:
Parameters: {"qqfile"=>"Foo.png"} {"qqfile"=>"Foo.png", "action"=>"ul_file", "controller"=>"upload_files"}
但我不能用它作为文件和做事情
thefile = params[:qqfile] foo = thefile.original_filename.slice(thefile.original_filename.rindex("."), thefile.original_filename.length).downcase
我需要做些什么来使这个脚本与Ruby on Rails一起工作?
谢谢。
///////// 更新
这就是JS的样子
$(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' }); });
$(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' }); });
我的解决方案在此评论中发布
我写QqFile以方便上传。 用回形针示例
这是使用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
语法看起来像这样,就像一个魅力:
file = CarrierwaveStringIO.new(params[:qqfile], request.raw_post)