43
loading...
This website collects cookies to deliver better user experience
def deletable_from_admin
!order.validated? && deleted_at.blank?
end
def destroy
order.context == :update_from_admin_space ? update!(deleted_at: Time.current) : super
end
controller do
def update
resource.context = :update_from_admin_space
super
end
end
f.inputs do
f.has_many :order_payments, new_record: !order.payment_accepted?, allow_destroy: :deletable_from_admin do |order_payment|
if order_payment.object.deleted_at.blank?
order_payment.input :expected_at,
...
deleted_at
and fill it with an update
whenever destroy
has normally to be called.has_many
instead of the real association. def destroy
update(deleted_at: Time.current)
end
destroy
new behaviour in the context of a deletion from Active Admin only. So I continued to check the code of the app to finally found an interesting line in models/order_payments.rb:controller do
def update
resource.context = :update_from_admin_space
...
destroy
method to use soft deletion only in the case of an update from the admin space. I'm still not fully satisfied, but it seems better than my initial solution.def destroy
order.context == :update_from_admin_space ? update(deleted_at: Time.current) : super
end
f.inputs do
f.has_many :order_payments, new_record: !order.payment_accepted?, allow_destroy: !order.validated? do |order_payment|
if order_payment.object.deleted_at.blank?
order_payment.input :expected_at,
...
allow_destroy
magically made the checkbox appear for each soft deleted record...It is possible to associate :allow_destroy with a string or a symbol, corresponding to the name of a child object’s method that will get called, or with a Proc object.
allow_destroy
condition somewhere and change the rule to return false
whenever I'm dealing with a soft deleted record:def deletable_from_admin
!order.validated? && deleted_at.blank?
end