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
-~----------~----~----~----~------~----~------~--~---