简体   繁体   English

Rails,回形针无法保存文件

[英]Rails, Paperclip Failing to Save File

So I'm using Thoughtbot's Paperclip on Rails, but ran into a problem where all image attributes are null: 所以我使用的是Thoughtbot的Paperclip on Rails,但是遇到了一个问题,其中所有图像属性均为null:

[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.

Scoured forums and the like for potential fixes and tutorials, tried each fix, but nothing. 搜寻论坛等以获取潜在的修复程序和教程,并尝试了每种修复程序,但未进行任何操作。 No warnings, errors, and fails silently. 没有警告,错误,并且无提示地失败。 Also, the included tests aren't working properly :( 另外,包含的测试无法正常进行:(

Running Ruby 1.8.6, Rails 2.3.3, and latest Paperclip (and also ImageMagick works since I use RMagick for another project) 运行Ruby 1.8.6,Rails 2.3.3和最新的Paperclip(由于我将RMagick用于另一个项目,因此ImageMagick也可以工作)

In the view, I have: 我认为:

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

In the controller, I have: 在控制器中,我有:

  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

My dev is on Windows, so I also tried the tempfile patch here: http://thewebfellas.com/blog/2008/11/2/goodbye-attachment_fu-hello-paperclip 我的开发人员在Windows上,因此我也在这里尝试了tempfile修补程序: http : //thewebfellas.com/blog/2008/11/2/goodbye-attachment_fu-hello-paperclip

I have the feeling that this is something ridiculous that I overlooked, so any comments would be helpful. 我感到这是我忽略的荒谬之处,因此任何评论都将有所帮助。 Thanks! 谢谢!

So the root cause was the ajax - though there is a POST call via ajax, the image information (and the corresponding attributes) are not sent in the header. 因此,根本原因是ajax-尽管通过ajax进行了POST调用,但是图像信息(以及相应的属性)未在标头中发送。 I think this might be something to do with the actual form behavior within the browser, so it would be great to get a reply from someone that knows how to get around this. 我认为这可能与浏览器中的实际表单行为有关,因此,最好是从知道如何解决此问题的人那里获得答复。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM