🖥
How to use Rails | ActiveDecorator outside View (such as Rspec test)
.name is an ordinary method. If .decorated_name is a decorated method.
It is natural, but .name can be used normally.
ExampleClass.first.name # => 'John'
However, the decorated method can not be used except in View.
ExampleClass.first.decorated_name # => NoMethodError: undefined method `decorated_method'
If it. Let's pass the instance body to ActiveDecorator's decorator method.
ActiveDecorator::Decorator.instance.decorate(ExampleClass.first).decorated_name # => '*J*o*h*n*'
OK now.
Original by
Rails | ActiveDecorator を View 以外で使う方法 ( Rspec テストなど )
About
チャットメンバー募集
何か質問、悩み事、相談などあればLINEオープンチャットもご利用ください。
公開日時
2019-04-16
Discussion