远程表单不张贴回形针附件 - Rails 3 [英] Remote forms not posting paperclip attachments - Rails 3

查看:53
本文介绍了远程表单不张贴回形针附件 - Rails 3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有回形针封面"附件的 Tour 模型.创建 Tour 模型后,它会很高兴地上传我选择的文件.这一切看起来像这样:

I have a Tour model with a paperclip 'cover' attachment. When the Tour model is created it will happily upload the file I've selected. It all looks something like this:

<% form_for [@user, @tour], :html => {:multipart => true} do |form| %>
 <%= form.text_field :title %>
 <%= form.file_field :cover %>
 <%= form.text_field :pic_url %>
 <%= form.submit 'go' %>
<% end %>

我最近重新实现了 Tour 的编辑操作,以便远程发布表单.我已经让远程表单运行良好,可以通过 ajax 发布和更新我的表单,但是当我希望更改封面"图像时,它并没有改变.远程表单看起来像这样:

I've recently re-implemented the edit action of Tour so the form is posted remotely. I've got the remote form working well posting and updating my form via ajax however when I wish to change the 'cover' image it doesn't change. The remote form looks something like this:

<%= form_for [@user, @tour], :remote => true, :update => "tour_form_holder", :html => {:multipart => true} do |form| %> 
 <%= form.text_field :title %>
 <%= form.file_field :cover %>
 <%= form.text_field :pic_url %>
 <%= form.submit 'go' %>
<% end %>

查看表单发布的数据,似乎它发布的数据与封面"无关 - 不像我发布没有 ajax 的表单.

Looking at the data posted by the form it doesn't seem as though it's posting anything to do with 'cover' - unlike when I posted the form without ajax.

然而,确实有效的一件事是使用表单将 url 发布到文件.我已将pic_url"设置为上传本地文件的替代方法.我知道这不会造成干扰,因为我已将其删除并尝试不使用它.

The one thing that does work however, is posting a url to a file using the form. I've set up 'pic_url' to be an alternative to uploading a local file. I know this isn't interfering because I've removed it and tried without it.

我知道 Amazon s3 和回形针正在工作 - 只是这个远程表单的一些东西不是......任何想法?

I know that Amazon s3 and paperclip are working - it's just something about this remote form that isn't... any ideas?

推荐答案

无法通过 AJAX 请求上传文件.有关更多详细信息,请参见此处:使用 php 通过 ajax 上传文件

It is not possible to upload a file via an AJAX request. See here for more details: uploading a file via ajax with php

这篇关于远程表单不张贴回形针附件 - Rails 3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆