【问题标题】:Ruby on rails: Remote Upload A File Using AJAXRuby on rails:使用 AJAX 远程上传文件
【发布时间】:2009-09-05 03:07:27
【问题描述】:

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

我试过这个没有成功:

<% remote_form_for @song,:html => { :multipart => true }, :url => { :action => 'upload' } do |f| %>

【问题讨论】:

  • 你得到什么样的错误?

标签: ruby-on-rails ajax


【解决方案1】:

如果您使用的是 Rails 3,请尝试使用 Remotipart gem。它使得 AJAX 风格的文件上传相对轻松。

http://rubygems.org/gems/remotipart

http://github.com/leppert/remotipart

【讨论】:

    【解决方案2】:

    标准的 remote_form_for 不理解多部分表单提交,因此如果没有上面 yoda 所示的一些工作,您实际上无法做到这一点。

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

    【讨论】:

      猜你喜欢
      • 2010-11-25
      • 1970-01-01
      • 1970-01-01
      • 2011-10-20
      • 1970-01-01
      • 1970-01-01
      • 2010-09-12
      • 2016-06-05
      • 2011-04-30
      相关资源
      最近更新 更多