Include Draper::ViewContextFilter in ActionMailer::Base
* Only send the :before_filter method if it exists * This will allow decorators to be used when rendering email
This commit is contained in:
parent
d72f2a1ee8
commit
c56ac5ed2c
|
@ -229,6 +229,21 @@ Use the new methods in your views like any other model method (ex: `@article.pub
|
|||
<h1><%= @article.title %> <%= @article.published_at %></h1>
|
||||
```
|
||||
|
||||
### 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:
|
||||
|
|
|
@ -2,6 +2,7 @@ module Draper
|
|||
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
|
|
@ -15,7 +15,7 @@ module Draper
|
|||
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
|
Loading…
Reference in New Issue