Activeadmin has_many表单仅用于显示和编辑

时间:2013-08-25 17:03:00

标签: ruby-on-rails-4 activeadmin polymorphism

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

但结果如下:

enter image description here

  1. 如何摆脱删除按钮并提交
  2. 我怎样才能在节目和编辑表单上显示此表单,因为在父母之前生孩子是没有意义的
  3. 请指出代码中的错误。

1 个答案:

答案 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