Get the latest tech news
Build a minimal decorator with Ruby in 30 minutes
A while ago, I needed to add some view-related instance methods to a model. Decorators are my go-to pattern to handle this kind of logic. So, I built a minimal decorator from scratch, added a bunch of extra behaviors, only to end up abstracting all of that away. Follow along!
So I built a minimal decorator from scratch, added a bunch of extra behaviors, only to end up abstracting all of these away. When I can call teacher.colour_coded_availability in my views, the method retrieves a CSS class and adds it to the HTML<td> tag. I can create an ApplicationDecorator whose job is to handle instantiation, and forwarding method calls to the underlying record.
Or read this on Hacker News