首先请注意,我正在使用 rails 4 和 activeadmin rails 4 分支。https://github.com/gregbell/active_admin/tree/rails4
我有两个多态模型图片
class Picture < ActiveRecord::Base
belongs_to :picture_category
belongs_to :imageable, polymorphic: true
mount_uploader :image, ImageUploader
end
和船
class Ship < ActiveRecord::Base
has_many :pictures, as: :imageable
accepts_nested_attributes_for :pictures
end
和 activeadmin ship.rb
ActiveAdmin.register Ship do
form do |f|
f.inputs do
f.inputs
f.has_many :pictures, :sortable => :picture_categories do |ff|
ff.input :name
end
end
f.actions
end
controller do
def permitted_params
params.permit(:ship => [:name, :title, :short_desc, :description, :position, :pictures, :enabled, :ship_provider_id, :picture_category_id, :picture_id])
end
end
end
但结果是这样的:
- 如何摆脱删除按钮并提交
- 我如何仅在显示和编辑表单上显示此表单,因为在父母之前生孩子是没有意义的
请指出代码中的错误。