Skip to content

Instantly share code, notes, and snippets.

@skuroki
Last active August 29, 2015 14:17
Show Gist options
  • Save skuroki/f6184db0f0e66bc0fa64 to your computer and use it in GitHub Desktop.
Save skuroki/f6184db0f0e66bc0fa64 to your computer and use it in GitHub Desktop.
ActiveDecoratorでdecorateしたオブジェクトのhas_one/belong_to先のオブジェクトが自動でdecorateされるようにする ref: http://qiita.com/skuroki@github/items/087e0953583d259738a5
module AssociationDecorator
def reader(*args)
result = super
if self.owner.is_a?(ActiveDecorator::Helpers)
ActiveDecorator::Decorator.instance.decorate(result)
end
result
end
end
module ActiveRecord
module Associations
class SingularAssociation
prepend AssociationDecorator
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment