Wednesday, September 26, 2007

HOW TO HANDLE EXCEPTIONS ON RAILS

It is not nice to display an error page full of errors to the user who is using your web application when there is actually some error.Sounds weird, but its true.A layman would never liked to be thrown on a error page.To avoid error display to the user you can do the following in your rails application.

Go to [path of the rails applaication]/apps/config/environments/development.rb
and make a env variable as false in the file


config.action_controller.consider_all_requests_local = false(by default it will be true)


Go to [path of the rails applaication]/apps/controllers/application.rb
add the below text in above mentioned file.

def rescue_action_in_public(exception)
render :text => '[Your html body]'
end


def local_request?
false
end


Thats it .. now dont let your user know that what are you cooking in the other corner... simple na.....:)...Thanks to Raghavedra who helped me for this article

2 comments: