Why View Objects Are The Best Solution For Complex Page Logic In Rails
Logic in views should be extracted into separate objects to improve maintainability and testability.
Why logic in views is a bad idea? The main reason not to put the complex logic into your views is, of course, testing. I don’t want to say that it is impossible to test logic defined in views, but it is much more complicated. And, as a very lazy person, I don’t like doing an extra work. The second reason is that views should have as little embedded dynamic code as possible. This gives us much cleaner code which is easy to modify and maintain. In our company we have a few simple conventions about logic in views: The Use only one dot rule. Which is also known as the Law of Demeter. You should...