Hello! I was wondering, sometimes I raise an exception in my Rails apps, e.g.: raise SecurityError unless @post.user == logged_in_user Now: is there any way to catch that SecurityError exception somewhere and render a custom template? E.g., I want to render ''app/views/content/security_error.rhtml'' Does anyone know how to do this? Thanks a bunch, Rob
Hi Rob ~ You could put it in a begin/rescue block... begin SOMETHING THAT MIGHT FAIL HERE rescue WHEN IT FAILS DO STUFF HERE end ~ Ben On 3/16/06, Robert MannI <robmnl@gmail.com> wrote:> Hello! > > I was wondering, sometimes I raise an exception in my Rails apps, e.g.: > > raise SecurityError unless @post.user == logged_in_user > > > Now: is there any way to catch that SecurityError exception somewhere > and render a custom template? E.g., I want to render > ''app/views/content/security_error.rhtml'' > > > Does anyone know how to do this? > > > > Thanks a bunch, > Rob > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- Ben Reubenstein http://www.benr75.com
Hi Ben! Thanks, yeah. But I was wondering if there''s a way to globally catch them. Doesn''t Rails catch things like ActiveRecord::RecordNotFound? Maybe one can plugin custom error catching there. If I find anything I will update this thread. Thanks, Rob On 3/16/06, Ben Reubenstein <benr@x-cr.com> wrote:> Hi Rob ~ > > You could put it in a begin/rescue block... > > begin > SOMETHING THAT MIGHT FAIL HERE > rescue > WHEN IT FAILS DO STUFF HERE > end > > ~ Ben > > On 3/16/06, Robert MannI <robmnl@gmail.com> wrote: > > Hello! > > > > I was wondering, sometimes I raise an exception in my Rails apps, e.g.: > > > > raise SecurityError unless @post.user == logged_in_user > > > > > > Now: is there any way to catch that SecurityError exception somewhere > > and render a custom template? E.g., I want to render > > ''app/views/content/security_error.rhtml'' > > > > > > Does anyone know how to do this? > > > > > > > > Thanks a bunch, > > Rob > > _______________________________________________ > > Rails mailing list > > Rails@lists.rubyonrails.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > -- > Ben Reubenstein > http://www.benr75.com > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
i would be interested in this as well. let me know if you find anything. adam On 3/17/06, Robert MannI <robmnl@gmail.com> wrote:> > Hi Ben! > > Thanks, yeah. But I was wondering if there''s a way to globally catch > them. Doesn''t Rails catch things like ActiveRecord::RecordNotFound? > Maybe one can plugin custom error catching there. > > If I find anything I will update this thread. > > > Thanks, > Rob > > On 3/16/06, Ben Reubenstein <benr@x-cr.com> wrote: > > Hi Rob ~ > > > > You could put it in a begin/rescue block... > > > > begin > > SOMETHING THAT MIGHT FAIL HERE > > rescue > > WHEN IT FAILS DO STUFF HERE > > end > > > > ~ Ben > > > > On 3/16/06, Robert MannI <robmnl@gmail.com> wrote: > > > Hello! > > > > > > I was wondering, sometimes I raise an exception in my Rails apps, e.g > .: > > > > > > raise SecurityError unless @post.user == logged_in_user > > > > > > > > > Now: is there any way to catch that SecurityError exception somewhere > > > and render a custom template? E.g., I want to render > > > ''app/views/content/security_error.rhtml'' > > > > > > > > > Does anyone know how to do this? > > > > > > > > > > > > Thanks a bunch, > > > Rob > > > _______________________________________________ > > > Rails mailing list > > > Rails@lists.rubyonrails.org > > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > > > > > -- > > Ben Reubenstein > > http://www.benr75.com > > _______________________________________________ > > Rails mailing list > > Rails@lists.rubyonrails.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060317/42d7eccf/attachment.html
On 17 Mar 2006, at 14:39, Adam Denenberg wrote:> i would be interested in this as well. let me know if you find > anything. >It''s actually very simple, check out recipe 31 from the Rails Recipes book: Getting Notified of Unhandled Exceptions. It also elaborates on how to get notified by mail if an exception occurs. Basically, you need to override the rescue_action_in_public method from ActionController. Best regards Peter De Berdt