【问题标题】:Rails, Paperclip Failing to Save FileRails,回形针无法保存文件
【发布时间】:2010-12-31 14:16:53
【问题描述】:

所以我在 Rails 上使用 Thoughtbot 的 Paperclip,但遇到了所有图像属性都为空的问题:

[4;35;1mProject Create (0.0ms)[0m   [0mINSERT INTO `projects` (`name`, `start_date`, `status`, `image_file_size`, `updated_at`, `url`, `image_content_type`, `description`, `progress`, `image_updated_at`, `created_at`, `image_file_name`) VALUES('dsfg', '2010-01-01', 'asdf', NULL, '2010-01-01 10:42:18', 'asfd', NULL, 'sdfg', 0, NULL, '2010-01-01 10:42:18', NULL)[0m
[paperclip] Saving attachments.

搜索了论坛等潜在的修复和教程,尝试了每个修复,但没有。没有警告、错误和静默失败。此外,包含的测试无法正常工作:(

运行 Ruby 1.8.6、Rails 2.3.3 和最新的 Paperclip(ImageMagick 也可以工作,因为我将 RMagick 用于另一个项目)

在视图中,我有:

form_for project, :html => {:class => "ajaxForm", :multipart => true} do |f|
...
= f.file_field project.image.url

在控制器中,我有:

  has_attached_file :image
  attr_accessible :image
  attr_accessible :status, :name, :start_date, :url, :progress, :description
  attr_accessible :image_file_name, :image_content_type, :image_file_size, :image_created_at, :image_updated_at
  #I also tried having just the :image line or the image attributes line, but no go

我的开发者在 Windows 上,所以我也在这里尝试了临时文件补丁:http://thewebfellas.com/blog/2008/11/2/goodbye-attachment_fu-hello-paperclip

我觉得这是我忽略的可笑之处,因此任何 cmets 都会有所帮助。谢谢!

【问题讨论】:

    标签: ruby-on-rails paperclip uploading


    【解决方案1】:

    所以根本原因是 ajax - 尽管通过 ajax 进行了 POST 调用,但图像信息(和相应的属性)并未在标头中发送。我认为这可能与浏览器中的实际表单行为有关,因此很高兴能得到知道如何解决此问题的人的回复。

    【讨论】:

    • 不能通过 ajax 上传文件。您可以使用隐藏的 iframe 来模拟类似 ajax 的行为。
    • 谢谢。比我想象的要容易得多 - kpumuk.info/ruby-on-rails/…
    猜你喜欢
    • 2018-04-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多