gneeot
2007-Jul-29 15:12 UTC
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. -- Regards Yuriy Padlyak --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Adam Gardiner
2007-Jul-29 23:18 UTC
Re: How to restrict deletion of ActiveRecord objects if ther
gneeot wrote:> > 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. >According to the Rails doc, all you need to do is return false from your before_destroy method. Here''s the relevant section: # == Cancelling callbacks # # If a before_* callback returns false, all the later callbacks and the associated action are cancelled. If an after_* callback returns # false, all the later callbacks are cancelled. Callbacks are generally run in the order they are defined, with the exception of callbacks # defined as methods on the model, which are called last. Hope this helps, Adam -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Bill Walton
2007-Jul-30 02:42 UTC
Re: How to restrict deletion of ActiveRecord objects if there dependent records?
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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
gneeot
2007-Jul-30 08:42 UTC
Re: How to restrict deletion of ActiveRecord objects if there dependent records?
thanks, will try it. On Jul 30, 5:42 am, "Bill Walton" <bill.wal...-xwVYE8SWAR3R7s880joybQ@public.gmane.org> wrote:> 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--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
gneeot
2007-Aug-06 16:23 UTC
Re: How to restrict deletion of ActiveRecord objects if there dependent records?
it works great, thank you. On Jul 30, 11:42 am, gneeot <YuraPadl...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> thanks, will try it. > > On Jul 30, 5:42 am, "Bill Walton" <bill.wal...-xwVYE8SWAR3R7s880joybQ@public.gmane.org> wrote: > > > 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--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---