The*_*ppe 4 ruby ruby-on-rails activeadmin
我的模型如下:
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
Run Code Online (Sandbox Code Playgroud)
这是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
Run Code Online (Sandbox Code Playgroud)
问题在于,当我只是编辑项目并单击更新项目时,它只是复制了该点上存在的关系的所有记录.例如.如果我在1个项目下有2个图像,在更改说,项目标题后,我将最终得到4个图像.
希望很清楚问题是什么.如果有人能给我一个小小的帮助,我将非常感激.
非常感谢提前.
nis*_*van 13
你必须允许图像的id: project_images_attributes: [:id, :image, :cover]
如果你不允许id,它在动作中将为null,并且rails认为它是一个新记录并保存它.
| 归档时间: |
|
| 查看次数: |
1028 次 |
| 最近记录: |