wearefine / fae

CMS for Rails. For Reals.

Home Page:https://www.faecms.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Delete action can raise error if the object has related items

asecondwill opened this issue · comments

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?

What is the exception you are getting and what does your model look like?

I usually put a dependent: :restrict_with_error on the association and this seems to work.
Example:

has_many :items, dependent: :restrict_with_error