How to restrict deletion of ActiveRecord objects if there dependent records?

Hi guys,

Trying to find some way to restrict deletion of ActiveRecord objects
if there dependent records.

I'm thinking of using before_destroy for it, but don't know how to
"cancel" deletion in my code in before_destroy "decides" that deletion
should be restricted.

Thank you in advance.

Hi Yuryi,

Trying to find some way to restrict deletion of ActiveRecord objects
if there dependent records.

I'm thinking of using before_destroy for it, but don't know how to
"cancel" deletion in my code in before_destroy "decides" that deletion
should be restricted.

I'm pretty sure that if a "before_" filter returns false, the whole action is canceled. Check the class docs at api.rubyonrails.org to be sure.

HTH,
Bill

thanks, will try it.

it works great, thank you.