Delete action can raise error if the object has related items
asecondwill opened this issue · comments
will commented
Fae's delete error is:
This item has associated objects that prevent it from being removed.
But it doesn't display that in that case, it raises an exception.
I'ved fixed this locally but added a delete method to my controller:
def destroy
if @item.destroy
redirect_to @index_path, notice: t('fae.delete_notice')
else
redirect_to @index_path, flash: { error: t('fae.delete_error') }
end
rescue
redirect_to @index_path, flash: { error: t('fae.delete_error')}
end
end
Would this be a senisble addition to fae's basecontroller?
James Kurczodyna commented
What is the exception you are getting and what does your model look like?
Jeremy Clemans commented
I usually put a dependent: :restrict_with_error on the association and this seems to work.
Example:
has_many :items, dependent: :restrict_with_error