2017-07-07 68 views
0

回形針沒有上傳圖片。打印圖像所附對象的輸出以顯示沒有圖像上傳。回形針沒有上傳圖片,回滾

控制檯:

irb(main):011:0> b = Article.find(9) 
    Article Load (0.5ms) SELECT "articles".* FROM "articles" WHERE "articles"."id" = ? LIMIT ? [["id", 9], ["LIMIT", 1]] 
=> #<Article id: 9, title: "Rails", body: "Server", created_at: "2017-07-07 15:05:41", updated_at: "2017-07-07 15:05:41", image_ 
file_name: nil, image_content_type: nil, image_file_size: nil, image_updated_at: nil> 
irb(main):012:0> 

日誌:

Command :: file -b --mime "C:/Users/addis/AppData/Local/Temp/4d3d12fcec1dd8d0eff643aa438c2b9120170708-9872-8pkize.jpg" 
[paperclip] Content Type Spoof: Filename 2006-05-09_01.19.32.jpg (image/jpeg from Headers, ["image/jpeg"] from Extension), conte 
nt type discovered from file command: . See documentation to allow this combination. 
Command :: file -b --mime "C:/Users/addis/AppData/Local/Temp/4d3d12fcec1dd8d0eff643aa438c2b9120170708-9872-knt072.jpg" 
[paperclip] Content Type Spoof: Filename 2006-05-09_01.19.32.jpg (image/jpeg from Headers, ["image/jpeg"] from Extension), conte 
nt type discovered from file command: . See documentation to allow this combination. 
    (0.0ms) rollback transaction 
Redirected to http://localhost:3000/articles/1 
Completed 302 Found in 49ms (ActiveRecord: 0.5ms) 

輔助方法:

module ArticlesHelper 

    def article_params 
    params.require(:article).permit(:title, :body, :tag_list, :image) 
    end 

end 

型號:

class Article < ApplicationRecord 
    has_many :comments 
    has_many :taggings 
    has_many :tags, through: :taggings 
    has_attached_file :image 
    validates_attachment_content_type :image, :content_type => ["image/jpg", "image/jpeg", "image/png"] 

    def tag_list 
    self.tags.collect do |tag| 
     tag.name 
    end.join(", ") 
    end 
    def tag_list=(tags_string) 
     tag_names = tags_string.split(",").collect{|s| s.strip.downcase}.uniq 
     new_or_found_tags = tag_names.collect {|name| Tag.find_or_create_by(name: name)} 
     self.tags = new_or_found_tags 
    end 
end 

使用可視代碼在Windows 10上運行。

繼此guide

回答

0

我認爲如果是回滾,問題來自您的驗證。 下面是validates_attachment的示例代碼格式,可能您可以試試

has_attached_file :image 
validates_attachment :image, :content_type => { :content_type => ["application/octet-stream","image/jpg","image/jpeg","image/png"] } 
+1

感謝您的回覆。我試過你的解決方案無濟於事。但是,我發現了一個反映我的問題的github問題:https://github.com/thoughtbot/paperclip/issues/2241 – Carrein

相關問題