🖥

How to use Rails | ActiveDecorator outside View (such as Rspec test)

2019/04/16に公開

.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

About this translattion

チャットメンバー募集

何か質問、悩み事、相談などあればLINEオープンチャットもご利用ください。

https://line.me/ti/g2/eEPltQ6Tzh3pYAZV8JXKZqc7PJ6L0rpm573dcQ

Twitter

https://twitter.com/YumaInaura

公開日時

2019-04-16

Discussion