We're going to use ActiveSupport::Concern to create a mixin to alter the behavior of something in our app. E.g., you might extract the tagging functionality in your blog to be a generic Taggable concern that you could extract for use in another app (or even make into a gem/engine). "Mixins" like this help us reduce redundancies and organize code even if the concern is only used in one class.
Read about "composition over inheritance" and "single responsibility principle" for more on the philosophical reasons we might do this.
[ ] Pick any one of your apps you've worked on so far. E.g., your blog app, one of the weekend projects, etc.
[ ] Use ActiveSupport::Concern in some way to define some functionality of one or more of your models.
Week 9 - Assignment 2
Mixins and
ActiveSupport::Concern
We're going to use
ActiveSupport::Concern
to create a mixin to alter the behavior of something in our app. E.g., you might extract the tagging functionality in your blog to be a genericTaggable
concern that you could extract for use in another app (or even make into a gem/engine). "Mixins" like this help us reduce redundancies and organize code even if the concern is only used in one class.Read about "composition over inheritance" and "single responsibility principle" for more on the philosophical reasons we might do this.
ActiveSupport::Concern
in some way to define some functionality of one or more of your models.Resources
Here are some recommended reads on the subject:
ActiveSupport::Concern
Documentation