Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add decorates_assigned method to controllers #461

Merged
merged 3 commits into from
Feb 7, 2013
Merged

Add decorates_assigned method to controllers #461

merged 3 commits into from
Feb 7, 2013

Conversation

haines
Copy link
Contributor

@haines haines commented Feb 7, 2013

I gave the decorates_assigned feature I mentioned a whirl.

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

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

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!

If the context of the owner decorator changes, the default context
of the decorated association should change too.
steveklabnik added a commit that referenced this pull request Feb 7, 2013
Add decorates_assigned method to controllers
@steveklabnik steveklabnik merged commit 916a1a6 into drapergem:master Feb 7, 2013
@steveklabnik
Copy link
Member

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants