2016-07-31 77 views
0

我正在使用activeadmin的car資源和多個附件沒有進入記錄,car記錄創建成功,但在創建時它不包含附件。我有兩個型號「附件」,models/attachment.rbActiveadmin多態關聯,回形針附件

class Attachment < ActiveRecord::Base 
    belongs_to :imageable, polymorphic: true 

    has_attached_file :avatar, styles: { medium: "300x300>", thumb: "100x100>" },default_url: "/images/:style/missing.png" 
    validates_attachment_content_type :avatar, content_type: /\Aimage\/.*\Z/ 
end 

而且 和我model/car.rb包含下面的代碼

class Car < ActiveRecord::Base 
    has_many :attachments, as: :imageable 
    accepts_nested_attributes_for :attachments 
end 

,在我app/admin/car.rb我爲多個連接下面的代碼。

form do |f| 
    f.input :make 
    f.input :model 
    f.input :color 
    f.input :engine_type 
    f.input :description 
    f.has_many :attachments do |attachment| 
    attachment.input :attachment, :as => :file 
    end 
    f.actions 
end 

任何人都可以請解釋如何解決這個問題?

+0

可以顯示你permit_params你'管理員/ car.rb'? – nayiaw

+0

當您嘗試保存/創建記錄時,日誌文件會說明什麼? – Eric

回答

0

我覺得你的輸入字段應該是:分身來代替:附件

所以,它應該看起來像

f.has_many :attachments do |attachment| 
    attachment.input :avatar, :as => :file 
end 
+0

也需要形成多部分 'form multipart:true do | f |' – Lance