jcasimir/draper — Issue #66: auto-decorate?
Author: aka47
Created: 2011-10-26 17:53:19+00:00
State: open

we have a complex domain logic and of course too complicated views. So drapper looks quite nice. But our pages are most of the time mixed resources, a user - has-many x which belongs to y.

In the view we are using helpers from all this objects.

A simple and powerful solution is to auto-decorate any Model via method-missing if we are in a view...

```ruby
class MyModel < ActiveRecord::Base

...

def decorator
@decorator ||= MyModelDecorator.new(self)
end

def method_missing(method_name, *args, &block)
Rails.logger.error("method_name #{method_name}")
#Rails.logger.error(Draper::ViewContext.current)
super(method_name, *args, &block) unless Thread.current[:current_view_context]

begin
decorator.send(method_name, *args, &block)
rescue NoMethodError
super
end
end
end
```

but i am not sure if this i too powerful and it also could create way too many objects under the hood.
What do you think?