active_decorator icon indicating copy to clipboard operation
active_decorator copied to clipboard

Cannot use decorator methods in decorator

Open wenbo opened this issue 5 years ago • 2 comments

It's okay to use decorator methods in actionview, but just like the following case, if I use decorator method in other decorator, it will be confronted with error.

it will be wonderful if it's possible to use decorator methods in decorator. that's the feature that needed in my situation. Any ideas please.

module ClassADecorator
  def mtd_a
    "this is mtd a"
  end
end

module ClassBDecorator
  def mtd_b
    # error, undefined method `mtd_a' for #<ClassA>
    ClassA.new.mtd_a 
  end
end

wenbo avatar May 18 '20 12:05 wenbo

The readme mentions:

ActiveDecorator::Decorator.instance.decorate(ClassA.new).mtd_a

vendethiel avatar May 18 '20 13:05 vendethiel

@vendethiel

thanks for your reply. just because there are so many ClassA.new.mtd_a, so what I need is without decorate manually, it's able to use decorator methods in decorator by default.

wenbo avatar May 18 '20 13:05 wenbo