Custom error message when destroying

84 views
Skip to first unread message

Doug

unread,
Dec 13, 2009, 1:14:49 PM12/13/09
to ActiveScaffold : Ruby on Rails plugin
Hi

I have some rules that require validation before a record gets
destroyed. I'm currently using before_destroy in the model, and can
prevent the destroy if necessary through returning false or raising an
exception.

AS, however, always displays the following warning "XYZ can't be
destroyed". How do I ask AS to display a custom error message (e.g.
"XYZ can't be destroy because of ABC"), in a similar way to
errors.add_to_base(...) when using validate for create/update, but
rather for destroy?

Thanks.

Sergio Cambra .:: entreCables S.L. ::.

unread,
Dec 14, 2009, 4:37:32 AM12/14/09
to actives...@googlegroups.com
You can override do_destroy with:
def do_destroy
destroy_find_record
begin
self.successful = @record.destroy
rescue Exception => ex
flash[:warning] = your_custom_message
self.successful = false
end
end


--
Sergio Cambra .:: entreCables S.L. ::.
Mariana Pineda 23, 50.018 Zaragoza
T) 902 021 404 F) 976 52 98 07 E) ser...@entrecables.com

Reply all
Reply to author
Forward
0 new messages