我得通過相關聯的的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
也不起作用。有誰知道如何使它工作?
我會發佈一個問題 – Gregg