0

首先请注意,我正在使用 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

但结果是这样的:

在此处输入图像描述

  1. 如何摆脱删除按钮并提交
  2. 我如何仅在显示和编辑表单上显示此表单,因为在父母之前生孩子是没有意义的

请指出代码中的错误。

4

1 回答 1

0

我知道如何解决第一个问题/您需要为嵌套资源输入插入:提交操作而不是按钮。例子:

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
于 2013-10-06T18:19:44.973 回答