Ruby on rails Rails、回形针无法保存文件

Ruby on rails Rails、回形针无法保存文件,ruby-on-rails,paperclip,uploading,Ruby On Rails,Paperclip,Uploading,所以我使用了Thoughtbot的回形针,但遇到了一个问题,即所有图像属性都为空: [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`, `cre

所以我使用了Thoughtbot的回形针,但遇到了一个问题,即所有图像属性都为空:

[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和最新的曲别针(还有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上,因此我也在此处尝试了tempfile修补程序:


我觉得这是我忽略的可笑的事情,所以任何评论都会很有帮助。谢谢!

所以根本原因是ajax——尽管有一个通过ajax的POST调用,图像信息(以及相应的属性)不是在标题中发送的。我认为这可能与浏览器中的实际表单行为有关,因此,如果能从知道如何解决此问题的人那里得到答复,那就太好了。

您不能通过ajax上传文件。您可以使用隐藏的iframe来模拟类似ajax的行为。谢谢。比我想象的简单多了-