Rails Best Practices 4: Put method in the right model

Logo devnterface d88f51727b3053dd3115e1ef9c566ad79b4c2edb3cd208c06345fc37058bebd9

In today’s post I will show some optimization we can do for models. I’ll focus on how to put methods inside the right model and delegation to get a better code.1. Put method in the right modelIn our example, suppose we want to represent the animal world by creating a model Kind that represents types of animal and an Animal models representing animals. For each type (quadrupedal, bipedal, bird) there are different animals that justify the has_many: animals relation defined in the followin...

Read more