2016-11-06 2 views
0

Active Admin을 사용하고 프로젝트에 대한 사진을 업로드해야합니다. 어떻게해야합니까? 내 코드 :액티브 관리자 다중 이미지 클립 클립으로 레일 업로드 5

class Project < ApplicationRecord 
    has_many :images 
    accepts_nested_attributes_for :images 
end 

class Image < ApplicationRecord 
    belongs_to :project 
    has_attached_file :image 
    validates_attachment_presence :image 
end 


ActiveAdmin.register Project do 

permit_params :project_name , :project_location , :project_status , :project_area , :project_prices , :project_info , :project_description , :image , :image_file_name, :image_content_type, :image_file_size, :image_updated_at 

    index do 
    column :project_name 
    column :project_description 
    actions 
    end 

    form :html => { :enctype => "multipart/form-data" } do |f| 
    f.inputs 'Project Info' do 
     f.input :project_name 
     f.input :project_description 
    end 

    f.inputs do 
     f.has_many :images do |p| 
     p.input :image , as: :file 
     end 
    end 

    f.actions 
    end 

end 

이 코드를 사용하면 이미지없이 프로젝트를 만들 수 있습니다. 그러나 나는 db에 어떤 이미지도 추가 할 수 없다. 도움을 기다리고 있습니다!

답변

1

나는 문제를 해결합니다! 작업 코드 : 나는이 그리워

permit_params :project_name , :project_location , :project_status , :project_area , :project_prices , :project_info , :project_description , images_attributes: [:image , :id , :_destroy] 


    f.inputs do 
     f.has_many :images , heading: false, allow_destroy: true do |ff| 
     ff.input :image, required: true, as: :file 
     end 
    end 

가장 중요한 부분 : 완전히이 부분을 작성하지 않는 경우 images_attributes: [:image , :id , :_destroy], 그것은 작동하지 않습니다!

관련 문제