josevalim/inherited_resources — Issue #197: Support DeleteRestrictionError
Author: brodock
Created: 2012-01-21 01:48:27+00:00
State: open

As of ActiveRecord 3, you can now declare a model relation with :dependent => :restrict. It is basically a referencial integrity check that, if the association exists, deny delete/destroying the model.

If a destroy command is issued, according to the documentation: http://apidock.com/rails/v3.0.9/ActiveRecord/DeleteRestrictionError it will throw ActiveRecord::DeleteRestrictionError.

My suggestion here is that InheritedResources surrounds destroy action with a begin/rescue to catch this specific expection and delegates to respond_with_dual_blocks so that a flash/error message can be sent to the user telling that it cannot be done.