diff --git a/Readme.markdown b/Readme.markdown
index 56baff9..a57d7b3 100644
--- a/Readme.markdown
+++ b/Readme.markdown
@@ -229,6 +229,21 @@ Use the new methods in your views like any other model method (ex: `@article.pub
<%= @article.title %> <%= @article.published_at %>
```
+### Using in Mailers
+
+To use decorators in mailers that use helpers, you have to call `set_current_view_context` in your
+mailer method:
+
+```ruby
+class ActicleMailer < ActionMailer::Base
+ def new_article(article)
+ set_current_view_context
+ @article_decorator = ArticleDecorator.decorate(article)
+ mail(:to => 'come@me.bro', :subject => "New Article: #{@article_decorator.title}")
+ end
+end
+```
+
## Possible Decoration Methods
Here are some ideas of what you might do in decorator methods:
diff --git a/lib/draper/system.rb b/lib/draper/system.rb
index 29cf957..3cf420c 100644
--- a/lib/draper/system.rb
+++ b/lib/draper/system.rb
@@ -1,7 +1,8 @@
module Draper
- class System
+ class System
def self.setup
ActionController::Base.send(:include, Draper::ViewContextFilter) if defined?(ActionController::Base)
+ ActionMailer::Base.send(:include, Draper::ViewContextFilter) if defined?(ActionMailer::Base)
end
end
-end
\ No newline at end of file
+end
diff --git a/lib/draper/view_context.rb b/lib/draper/view_context.rb
index 6b5ab21..8a0bb13 100644
--- a/lib/draper/view_context.rb
+++ b/lib/draper/view_context.rb
@@ -8,14 +8,14 @@ module Draper
Thread.current[:current_view_context] = input
end
end
-
+
module ViewContextFilter
def set_current_view_context
Draper::ViewContext.current = self.view_context
end
-
+
def self.included(source)
- source.send(:before_filter, :set_current_view_context)
+ source.send(:before_filter, :set_current_view_context) if source.respond_to?(:before_filter)
end
end
-end
\ No newline at end of file
+end