Posts

Showing posts from January, 2016

Easy error handling in Rails

Image
Let me start by asking what do you think about errors? Many people hate errors and are trying to avoid them as much as possible. But today I want to show how errors can make your life easier! Let's say user submitted some form in your application. Where do you check if it's valid? In the controller? Controller's should not be concerned with all that is going on in our models. Should the controller ask a model if data is valid or not? Model should be already checking incoming data.What is you introduce some change deep inside your code, you can't expect to know all the place where it's used! In Java World (and in others) errors are not actually called "errors", they are called "exceptions" and they can help you to handle exceptional situations. Ruby language has similar exception system. Errors can be raised and rescued. Let's distinguish between 2 types or errors. 1) Ones that we can actually anticipate and fix. 2) All