I'm using Draper gem for decorators.
I have two similar models, that doing the same, but using different databases.
In my namespaces I have prefix Clone::. So, for instance: Car and Clone::Car.
I already have a decorator CarDecorator for Car model. All I want is to use this decorator for Clone::Car as well, but when I'm trying to apply such code by using inheritance:
class Clone::CarDecorator < CarDecorator
end
I have an error in my specs:
Circular dependency detected while autoloading constant
Clone::Car.
What is the best practice to implement single decorator per multiple models via Drapper gem?
There were no answers, so I will post my solution. It's possible to do this without inheritance and adding additional decorator by adding method
#decorator_classinto "child" class. So, according to the example above, it will looks like:So, by such means,
CarDecoratorwill be using in theCarmodel andCloneCarmodel as well.