lib/draper/decoratable.rb in draper-1.1.0 vs lib/draper/decoratable.rb in draper-1.2.0
- old
+ new
@@ -50,20 +50,23 @@
# @example
# Product.popular.decorate
# @param [Hash] options
# see {Decorator.decorate_collection}.
def decorate(options = {})
- decorator_class.decorate_collection(self.scoped, options)
+ collection = Rails::VERSION::MAJOR >= 4 ? all : scoped
+ decorator_class.decorate_collection(collection, options.reverse_merge(with: nil))
end
# Infers the decorator class to be used by {Decoratable#decorate} (e.g.
# `Product` maps to `ProductDecorator`).
#
# @return [Class] the inferred decorator class.
def decorator_class
prefix = respond_to?(:model_name) ? model_name : name
- "#{prefix}Decorator".constantize
- rescue NameError
+ decorator_name = "#{prefix}Decorator"
+ decorator_name.constantize
+ rescue NameError => error
+ raise unless error.missing_name?(decorator_name)
raise Draper::UninferrableDecoratorError.new(self)
end
# Compares with possibly-decorated objects.
#