I have used draper with some success. But currently I'm stuck.
I have two models:
# 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
If the class is loaded normally, it works as expected:
f = Foo.find(1)
f.bars.number_banned # ex. 3
If I use Draper to decorate the objects, it returns an undefined "number_banned" method:
f = Foo.find(1).decorate
f.bars.number_banned # Undefined method 'number_banned'
To note:
- Both Decorators include the delegate_all option
- FooDecorator decorates_association :bars
Any Ideas what I'm doing wrong?