首先请注意我正在使用rails 4和activeadmin rails 4分支。 https://github.com/gregbell/active_admin/tree/rails4
我有两个模型图片是ploymorphic
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
但结果如下:
请指出代码中的错误。
答案 0 :(得分:0)
我知道如何解决第一个问题/ 您需要为嵌套资源输入插入:submit 操作代替按钮。例如:
form do |ship|
ship.inputs t(:ship_details) do
ship.input :name, :label => t(:name)
ship.input :description, :label => t(:description)
ship.has_many :pictures do |picture|
picture.input :url
picture.input :imgdescription
picture.actions do
picture.action :submit
end
end
end
end