2017-10-20 173 views
0

我得通過相關聯的的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也不起作用。有誰知道如何使它工作?

回答

2

奇怪

從它看起來像不包括: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

+0

我會發佈一個問題 – Gregg

相關問題