我的型號如下:導軌 - activeadmin,在更新的「父」記錄重複的has_many記錄
class Project < ActiveRecord::Base
has_many :project_images
accepts_nested_attributes_for :project_images
end
class ProjectImage < ActiveRecord::Base
belongs_to :project
mount_uploader :image, ImageUploader
end
這裏的activeadmin文件:
ActiveAdmin.register Project do
remove_filter :projects_sectors
permit_params :title, :info, :case_study, project_images_attributes: [:image, :cover]
index do
column :title
actions
end
form :html => { :enctype => "multipart/form-data" } do |f|
f.inputs "Project" do
f.input :title
f.input :info
f.input :case_study, :as => :file
end
f.inputs "Images" do
f.has_many :project_images, :allow_destroy => true, :heading => false, :new_record => true do |img_f|
img_f.input :image, :as => :file , :hint => f.template.image_tag(img_f.object.image)
img_f.input :cover
end
end
f.actions
end
end
的問題是,當我簡單地編輯項目並點擊更新項目,它只是複製當時關係中存在的所有記錄。例如。如果我在1個項目下有2個圖像,在改變後說出項目標題,我將以4個圖像結束。
希望很清楚問題所在。如果有人能給我一點幫助,我會很感激。
非常感謝。
我還沒有時間來測試這個呢。但它總是有意義的。所以你得到賞金:) –
謝謝。 :D我有同樣的問題,這是解決方案。 – nistvan