| Start |
|---|
| Decorating a Model using SimpleDelegator Most Rails developers start by modifying their model information within the template itself: For models with a lot of data, this can quickly become cumbersome and lead to copy-pasting logic from one template to another. This example uses All requests to a
Some decorators rely on magic to wire-up this behavior, but you can make it more obvious where the presentation logic is coming from by initializing the object on the page. By passing a reference to the view object into the decorator, we can still access all of the rest of the view helpers while building the presentation logic without having to include it. Now the view template is only concerned with inserting data into the page, and it is much more clear. |
| Decorating a Model using Draper Draper automatically matches up models with their decorators by convention. Given a RemarksThe Decorator pattern (opens new window) allows you to add or modify behavior of objects in a situational way without affecting the base object. This can be achieved though plain Ruby using the stdlib, or via popular gems such as Draper (opens new window). |
Read Article
https://develop.horje.com/learn/1434/reference