Ich habe eine has_many durch Vereinigung bekam wie in unten:activeadmin has_many ausblenden Schaltfläche Entfernen
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
und eine activeadmin Seite:
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
Ich möchte 'entfernen Button' entfernen f.has_many
aber Ich kann es scheinbar nicht funktionieren lassen. Ich habe allow_destroy: false
verwendet, aber es funktioniert nicht einmal zu accepts_nested_resources
hinzufügen. Weiß jemand, wie es funktioniert?
Ich werde ein Problem veröffentlichen – Gregg