From the course: Ruby on Rails 6 Essential Training: Models and Associations

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Smart models by design

Smart models by design - Ruby on Rails Tutorial

From the course: Ruby on Rails 6 Essential Training: Models and Associations

Start my 1-month free trial

Smart models by design

- [Instructor] In the previous movie, I suggested thinking of methods as interfaces to an object. In this movie, we'll consider which interfaces make sense. We'll look at how to make models smarter by the design choices that we make. There's a common saying in the Ruby on Rails community. "Fat model, skinny controller." It's a general principle for organizing our code. Not a hard rule that you have to follow. The concept is that it's generally best to move your business logic out of the controller and into the model. In the process, your models become smarter because the business logic is there and you can access it and reuse it. One way to do that is to try to think about the kinds of things that an instance of a class should know about or know how to do and to define instance methods for those things. Then those instance methods can be called to return information based on attributes and associations that are…

Contents