josevalim/inherited_resources — Issue #181: Destroy do not show flash message when object.destroy returns false
Author: sobrinho
Created: 2011-12-06 19:26:51+00:00
State: open

Using ActiveRecord we can return false from any callback to stop the destroy but IR thinks it's was destroyed and show the success message.

The issue could be simplified by this:

``` ruby
class SomeController < InheritedResources::Base
def destroy_resource(object)
false
end
end
```

Currently I'm using this to workaround the issue:

``` ruby
def destroy(options={}, &block)
object = resource

if destroy_resource(object)
options[:location] ||= smart_collection_url
else
options[:location] ||= edit_resource_path
options[:alert] ||= t("flash.actions.destroy.alert", :resource_name => resource_class.model_name.human)
end

respond_with_dual_blocks(object, options, &block)
end
```