I'm using Draper gem in my Rails project to obtain decorator pattern functionality. I thought that gem will help to increase my productivity by separating model logic and view logic.
But overall workflow has become terrifying. I should always add .decorate
to the model in every controller.
My decorators classes are a net of delegate_all
between each other. Also when I started to use ActiveModel Serializers
, I had figured that serializers can't work with my decorators.
I don't like this approach and decided not to use a separate decorator class, but provide a Decorator Module for each model.
Is it OK? What problems could arise with this solution?
module UserDecorator
extend ActiveSupport::Concern
included do
def full_name
"{first_name} #{last_name}"
end
end
end
First of all, it's very simple. And I solve the next problems:
I don't need to work with decorated inherited class of model. I just provide decorator methods for the existing model class.
ActiveSerializer
can now use decorator methods.
But I feel that something is wrong with this solution. Please, give me some critics!