1

我有回形针网站上的所有默认设置。当我创建一个新应用程序并将设置放入时,一旦我保存了我的模型,“照片”回形针属性就会很好地保存,一切都很好(这里是 SQL INSERT 示例):

"photo"=>#<ActionDispatch::Http::UploadedFile:0x007f990a3d92d0
@original_filename="Screen Shot 2011-10-21 at 6.02.56 AM.png",
@content_type="image/png", @headers="Content-Disposition: form-data;
name=\"event[photo]\"; filename=\"Screen Shot 2011-10-21 at 6.02.56
AM.png\"\r\nContent-Type: image/png\r\n"

我得到:

[paperclip] Saving attachments

现在在我使用 Devise 和 Cancan 的其他应用程序中,我有完全相同的回形针设置,我确实得到了

[paperclip] Saving attachments.

但是,它不会保存“照片”,并且根本看不到照片属性被定义 。现在我看到了一个类似的帖子得到解决添加

attr_accessible photo

到模型,我做到了,但仍然无法正常工作。我在这上面浪费了这么多时间,有时我觉得我应该创建自己的图片上传......

任何想法?谢谢!

顺便说一下。我添加的简单脚手架对象上的相同问题

attr_accessible :照片

4

1 回答 1

1

If you're using a framework like jQuery Mobile or some sort of AJAX/PJAX mechanism, your uploads will be lost as POST in Ajax, since JS cannot read your local files...

You'll have to use some uploadify-like plugin or submit your form the "regular" way.

Edit: To make things clear, the easiest way will be to add data-ajax="false" as a form attribute. In Rails 3, using the form helper, you'd write something along those lines:

<%= form_for (@my_object, html: {data: {ajax: false}}) do |f| %>
    ...
<% end %>
于 2012-05-12T20:25:36.663 回答