Ruby on rails:使用AJAX远程上传文件

dev*_*oss 5 ajax ruby-on-rails

我已经使用PUT和html成功上传了一个文件,但有没有办法在ajax remote_form_for中上传文件?

我试过这个没有成功:

<% remote_form_for @song,:html => { :multipart => true }, :url => { :action => 'upload' } do |f| %>
Run Code Online (Sandbox Code Playgroud)

lep*_*ert 10

如果您使用的是Rails 3,请尝试使用Remotipart gem.它使AJAX样式文件上传相对轻松.

http://rubygems.org/gems/remotipart

http://github.com/leppert/remotipart


Tob*_*ede 2

标准的remote_form_for不\xe2\x80\x99不理解多部分表单提交,因此如果没有上面yoda指示的一些跑腿工作,你实际上无法做到这一点。

\n\n

实现此目的的另一种方法是使用 iframe。

\n