From 92d21468917ab72a8e1e02f124253ccacc0fa4af Mon Sep 17 00:00:00 2001 From: Jeff Casimir Date: Tue, 12 Jul 2011 14:29:08 -0700 Subject: [PATCH] Added link to tutorial / sample project --- Readme.markdown | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Readme.markdown b/Readme.markdown index 0090acd..2c76e55 100644 --- a/Readme.markdown +++ b/Readme.markdown @@ -12,7 +12,7 @@ This gem makes it easy to apply the decorator pattern to the models in a Rails a 2. Filter data at the presentation level 3. Enforce an interface between your controllers and view templates. -## 1. Object Oriented Helpers +### 1. Object Oriented Helpers Why hate helpers? In Ruby/Rails we approach everything from an Object-Oriented perspective, then with helpers we get procedural.The job of a helper is to take in data and output a presentation-ready string. We can do that job in an OO style with a decorator. @@ -30,7 +30,7 @@ class ArticleDecorator < Draper::Base end ``` -## 2. View-Layer Data Filtering +### 2. View-Layer Data Filtering Have you ever written a `to_xml` or `to_json` method in your model? Did it feel weird to put what is essentially view logic in your model? @@ -54,6 +54,10 @@ class ArticleDecorator < Draper::Base end ``` +### 3. Enforcing an Interface + +Notes about `denies` and `allows` go here! + ## How is it implemented? To implement the pattern in Rails we can: @@ -132,6 +136,8 @@ Here are some ideas of what you might do in decorator methods: ## Example Using a Decorator +For a brief tutorial with sample project, check this out: http://tutorials.jumpstartlab.com/rails/topics/decorators.html + Say I have a publishing system with `Article` resources. My designer decides that whenever we print the `published_at` timestamp, it should be constructed like this: ```html