2016-07-31 2 views
0

car 리소스에 activeadmin을 사용하고 있고 여러 첨부 파일이 레코드에 들어 가지 않아서 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

같이해야합니까? – nayiaw

+0

레코드를 저장/생성하려고 할 때 로그 파일의 내용은 무엇입니까? – Eric

답변

0

나는 당신의 입력 필드가 있어야한다고 생각 : 대신 아바타 : 첨부 파일을

그래서, 그것은 당신의 '관리자/car.rb` 대한 permit_params을 보여줄 수

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

폼도 멀티 파트 여야합니다. 'multipart : true do | f |' – Lance

관련 문제