Hi Patrice,
I''m going through this process of handling
"ActiveRecord::RecordNotFound" in my code, and your approach is the
cleanest I have found so far.
Thanks for posting,
Neville
-----Original Message-----
From: rails-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
[mailto:rails-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] On
Behalf Of Patrice Neff
Sent: Friday, 28 January 2005 2:52 AM
To: rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
Subject: [Rails] error handling
Hi,
I have recently started using Rails and am currently digging into it as
well as Ruby.
Now I was wondering how to best handle RecordNotFound errors with
showing a nice 404 page and still not writing too much code. I came up
with a method in the ApplicationController and calling that method with
a block.
The method looks like this:
def handle404(pagetitle)
begin
yield
rescue ActiveRecord::RecordNotFound
@page_title = pagetitle
render "layouts/error", 404
end
end
And I call it as follows:
handle404("Project not found") {
@project = Project.find(@params["id"])
@page_title = "Project: " + @project.title
}
See also my German explanation of this approach at
http://patrice.kaywa.ch/ruby_on_rails/fehler-behandlung_in_rails.html
Is this a practical way of doing this stuff? How do you generally do
this?
Patrice
--
the Holy Scriptures, which are able to make you wise for salvation
through faith in Christ Jesus. (2 Timothy 3:15)
_______________________________________________
Rails mailing list
Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
http://lists.rubyonrails.org/mailman/listinfo/rails