Sorry, I've read so fast your reply so I've mistake the code. Now I've try with this code (like you've write)
before_destroy :deletable def deletable products.blank? end and the validation is ok, but now no message appears (neither "Request Failed (code 500, Internal Error)"). I would to show the user that the delete operation is not permetted. How to do this in the Active Scaffold view? Thank you On 7 Nov, 17:12, Stefano <[EMAIL PROTECTED]> wrote: > Thank you for your reply. > I've try to use this code: > > before_destroy :deletable > > def deletable > unless products.blank? > raise "You can't destroy this invoice!" > end > end > > but the message in the view is always "Request Failed (code 500, > Internal Error)". > > What can I do? > > Thank you for your help > > On 7 Nov, 11:48, "Sergio Cambra .:: entreCables - Symbol Servicios > Informáticos S.L. ::." <[EMAIL PROTECTED]> wrote: > > > El Thursday 06 November 2008 16:46:23 Stefano escribió: > > > > Hi, I've a model called "Invoice" that :has_many products. > > > I've validate the destroy of one Invoice that control if the > > > invoice.products is empty (one invoice can't be deleted if contains > > > products). > > > Here the code: > > > ----------------------------------- > > > before_destroy :deletable > > > > def deletable > > > unless products == [] > > > raise "You can't destroy this invoice!" > > > end > > > end > > > ------------------------------------- > > > > The validation is ok so in the view (managed by ActiveScaffold) if I > > > try to delete one invoice with some products associated, I receive the > > > message "Request Failed (code 500, Internal Error)" and not "You can't > > > destroy this invoice!". > > > How can I change the message? > > > Thank you > > > ActionController callbacks must raise an exception or render or redirect to > > cancel the action, but ActiveRecord callbacks cancel actions returning > > false, > > so you should use: > > > def deletable > > products.blank? > > end > > -- > > Sergio Cambra .:: entreCables - Symbol Servicios Informáticos S.L. ::. > > Nicolás Guillén 6, locales 2 y 3. 50.018 Zaragoza > > T) 902 021 404 F) 976 52 98 07 E) [EMAIL PROTECTED] --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "ActiveScaffold : Ruby on Rails plugin" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/activescaffold?hl=en -~----------~----~----~----~------~----~------~--~---
