私はドレーパーを使用していくつかの成功を収めました。しかし、現在私は立ち往生しています。
私は2つのモデルを持っています:
# Foo.rb
class Foo < ActiveRecord::Base
has_many :bars
# Bar.rb
class Bar < ActiveRecord::Base
belongs_to :foo
def self.number_banned
where(:status => "banned").count
end
クラスが正常にロードされた場合、期待どおりに動作します。
f = Foo.find(1)
f.bars.number_banned # ex. 3
Draper を使用してオブジェクトを装飾すると、未定義の「number_banned」メソッドが返されます。
f = Foo.find(1).decorate
f.bars.number_banned # Undefined method 'number_banned'
注意します:
- どちらのデコレータにも delegate_all オプションが含まれています
- FooDecorator decores_association :bars
私が間違っていることはありますか?