chamnap/draper-extensions

View on GitHub
lib/draper/extensions/active_relation.rb

Summary

Maintainability
A
0 mins
Test Coverage
## This extension allow us to invoke `#decorate` on active_relation objects
##
## @products = listing.products.page(1).decorate
## @products => Draper::CollectionDecorator

if defined?(ActiveRecord)
  if ActiveRecord::VERSION::STRING.start_with?("4.") || ActiveRecord::VERSION::STRING.start_with?("3.2")
    class ActiveRecord::Relation
      def decorate
        klass.decorator_class.decorate_collection(self)
      end
    end
  end
end