如何使用“Ajax 上传”与 Ruby on Rails 一起使用吗?
我正在使用此脚本 http://valums.com/ajax-upload/ 来获取 Ajax 上传使用 Ruby on Rails,
但是当我尝试在控制器操作上上传文件时,我只得到以下信息:
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'
});
});
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'
});
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我的解决方案发布在 这个评论
我写QqFile是为了方便上传。以回形针为例
my solution posted in this comment
I write QqFile for easy uploader. With paperclip example
这是使用 CarrierWave 的一个很好的解决方案:
https://github.com/jnicklas/rierwave/wiki/How-to%3A-Upload-from-a-string-in-Rails-3
https://groups.google.com/forum/#!topic/rierwave/KBn2WmrwRAs
语法如下所示,并且工作起来就像一个魅力:
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: