Is there any easy way how to handle AJAX file upload in Rails? e.g. with a plugin
相关问题
- Carriage Return (ASCII chr 13) is missing from tex
- Question marks after images and js/css files in ra
- Using :remote => true with hover event
- Is there a way to play audio on a mobile browser w
- net::ERR_EMPTY_RESPONSE when post with ajax
相关文章
- spring boot用ajax发送请求后,请求路径多了controller的路径
- 针对复杂结构的前端页面,如何更好地与后台交互实现动态网页?
- ajax上传图片,偶尔会出现后台保存的图片有错误或者已损坏,请问可能是什么原因造成的?
- 前端 我想知道怎样通过发ajax请求向服务器拿到数据然后分页显示 最好是点击一页就发一次请求
- 接口返回的数据格式如下,请问可以取到level值为2的name数组呢
- 如何通过页面输入账号密码提交给后端
- How to get jQuery.ajax response status?
- Right way to deploy Rails + Puma + Postgres app to
If you're using Rails 3, I've written a plugin that makes AJAX style file uploads relatively trivial to implement.
http://rubygems.org/gems/remotipart
It's not really necessary to use some special plugins for that. Easiest way to do ajax picture upload for me was just make form that uploading pictures to act like ajax. For that I use ajaxForm jQuery plugin: http://www.malsup.com/jquery/form/ Than return to js uploaded picture and put it to your page.
So, you should make your form be ajaxForm:
controler looks like that:
and in ajaxFormSuccessHandler you simply get picture object:
and put photo wherever you like:
P.S: Don't really know why but if you return to ajaxForm handler something, it handle that request as ERROR not SUCCESS.
P.P.S: surely jQuery-File-Upload plugin makes more but if you don't need all that, you can use this way.
P.P.P.S: you should have already functional non-ajax file upload for do that =)
JQuery File Upload is very active and versatile file upload widget project.
See the demo here: http://blueimp.github.com/jQuery-File-Upload/
Here's a Gem: http://rubygems.org/gems/jquery.fileupload-rails
The wiki also has Rails examples: https://github.com/blueimp/jQuery-File-Upload/wiki
You can use Jquery Form
in your view (haml sample):
here is Rails app sample https://github.com/serghei-topor/ajax-file-upload-rails-sample