activeadmin的has_many隐藏删除按钮
问题描述:
我得通过相关联的的has_many如下:activeadmin的has_many隐藏删除按钮
class Room < ApplicationRecord
has_many :room_options
has_many :options, through: :room_options
accepts_nested_attributes_for :room_options, allow_destroy: false
end
class RoomOption < ApplicationRecord
belongs_to :room
belongs_to :option
end
class Option < ApplicationRecord
has_many :room_options
has_many :rooms, through: :room_options
end
和activeadmin页:
ActiveAdmin.register Room do
permit_params :name, :guests_capacity, :description, :price, photos_attributes: [:id, :image, :is_primary, :_destroy]
form(:html => { :multipart => true }) do |f|
f.inputs do
f.input :name
f.input :guests_capacity
f.input :description
f.has_many :photos, allow_destroy: true do |photo|
photo.input :image, as: :file,
hint: image_tag(photo.object.image_url(:thumb))
photo.input :is_primary
end
Option.find_each { |option| f.object.room_options.build(option: option)}
f.has_many :room_options, new_record: false, allow_destroy: false do |rof|
rof.input :option_id, as: :hidden
rof.input :has_option, as: :boolean, label: rof.object.option.name
end
f.input :price
end
f.actions
end
end
我想删除从f.has_many
'删除按钮',但我似乎无法使其工作。我使用了allow_destroy: false
,但即使将其添加到accepts_nested_resources
也不起作用。有谁知道如何使它工作?
答
奇怪
从它看起来像不包括:allow_destroy
的文件是不具有破坏选项的解决方案
ActiveAdmin.register Post do
form do |f|
f.inputs 'Details' do
f.input :title
f.input :published_at, label: 'Publish Post At'
end
f.inputs 'Content', :body
f.inputs do
f.has_many :categories, heading: 'Themes',
allow_destroy: true,
new_record: false do |a|
a.input :title
end
end
f.inputs do
f.has_many :taggings, sortable: :position, sortable_start: 1 do |t|
t.input :tag
end
end
f.inputs do
f.has_many :comment,
new_record: 'Leave Comment',
allow_destroy: -> { |c| c.author?(current_admin_user) } do |b|
b.input :body
end
end
f.actions
end
end
的:allow_destroy选项增加一个复选框,嵌套结束形式允许在提交时移除儿童物体。请务必在关联上设置allow_destroy:true以使用此选项。可以将:allow_destroy与一个字符串或符号相关联,对应于将被调用的子对象方法的名称,或与Proc对象相关联。 Proc对象将该子对象作为参数接收,并返回true或false。
也in some cases包括accepts_nested_attributes_for :images, allow_destroy: true
包括此选项
我不知道如何解决这个问题,也许你应该在自己的GitHub页面发布一个问题是必要的吗?
https://github.com/activeadmin/activeadmin/issues?utf8=%E2%9C%93&q=is%3Aissue%20is%3Aopen%20destroy
我会发布一个问题 – Gregg