ImageGallery를 제품과 연결하기위한 선택 메뉴를 설치하려고합니다. ImageGallery는 여러 모델에서 공유되므로 다형성을 갖습니다. Formtastic은해야 할 일에 대해 매우 혼란스러워합니다. 그것은 제품 모델에서 _id (galleryable_id)라는 다형성 연관의 이름 인 Galleryable이라는 메소드를 호출하려고합니다.활성 관리자가 하나의 다형성 양식을 가지고 있습니다.
제품
class Product < ActiveRecord::Base
has_one :image_gallery, as: :galleryable, dependent: :destroy
accepts_nested_attributes_for :image_gallery, :allow_destroy => true
end
갤러리
class ImageGallery < ActiveRecord::Base
belongs_to :galleryable, polymorphic: true
validates :title, presence: true
has_many :images, as: :imageable, dependent: :destroy
accepts_nested_attributes_for :images, :allow_destroy => true, reject_if: lambda { |t| t['file'].nil? }
end
내가 모델에 galleryable_id을 정의와 함께 연주하지만,이 속성을 가진 제품을 업데이트하려고
form do |f|
f.inputs "Details" do
f.input :name
f.input :category
f.input :price
f.input :purchase_path
f.input :video_panels
f.input :image_panels
f.input :image_gallery, :as => :select, collection: ImageGallery.all, value_method: :id
end
f.inputs "Image", :for => [:image, f.object.image || Image.new] do |i|
i.input :title
i.input :file, :as => :file, required: false, :hint => i.template.image_tag(i.object.file.url(:thumb))
end
f.actions
end
액티브 관리 양식하는 물론 존재하지 않습니다.
누구나 성공적으로 설정 했습니까?
감사합니다,
코리