views:

533

answers:

1

So I'm using Thoughtbot's Paperclip on Rails, but ran into a problem where all image attributes are 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)

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

I have the feeling that this is something ridiculous that I overlooked, so any comments would be helpful. Thanks!

A: 

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

You can't upload files via ajax. You can use hidden iframe to simulate ajax-like behavior.
Eimantas
Thanks. Much easier than I thought - http://kpumuk.info/ruby-on-rails/in-place-file-upload-with-ruby-on-rails/