2010-01-01 23 views
1

所以我使用Thoughtbot的回形針on Rails的,但遇到了一個問題,即所有的圖像屬性都爲空:Rails中,回形針未按規定保存文件

[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上,所以這裏我也嘗試了臨時文件的補丁:http://thewebfellas.com/blog/2008/11/2/goodbye-attachment_fu-hello-paperclip

我有這種感覺,這是荒謬的,我忽略了,所以任何意見都會有所幫助。謝謝!

回答

0

所以根本原因是ajax - 雖然有通過ajax的POST調用,圖像信息(和相應的屬性)不會在標題中發送。我認爲這可能與瀏覽器中的實際表單行爲有關,所以從知道如何解決此問題的人那裏得到答覆會很棒。

+1

您無法通過ajax上傳文件。您可以使用隱藏的iframe來模擬類似Ajax的行爲。 – Eimantas 2010-01-02 09:51:09

+0

謝謝。比我想象的要容易得多 - http://kpumuk.info/ruby-on-rails/in-place-file-upload-with-ruby-on-rails/ – user117046 2010-01-03 07:46:24