drapergem/draper — pull request #461 by haines (2013-02-07 01:10:13+00:00)
Title: Add decorates_assigned method to controllers

I gave the `decorates_assigned` feature I [mentioned](https://github.com/drapergem/draper/issues/446#issuecomment-12921366) a whirl.

I think it's quite nifty, basically it produces a helper method like this

```ruby
decorates_assigned :article
# generates
def article
return @decorated_article if defined?(@decorated_article)
@decorated_article = factory.decorate(@article)
end
helper_method :article
```

where the `factory` handles options and automagical guessing of collections, so that you can do things like

```ruby
decorates_assigned :article, with: FancyArticleDecorator
decorates_assigned :articles, with: PaginatingCollectionDecorator
```

It's very similar behaviour to `decorates_association`, and indeed, Factory is extracted from that class.

Then you just replace `@article` with `article` in your view, and away you go. No more getting bitten by immutable decorators in your controller actions.

See what you think!