Allows your users to edit e-mail templates. With Devise and Active Admin support (but you don't need them to start using email_template).
Add this line to your application's Gemfile:
gem 'email_template'
And then execute:
$ bundle
Or just:
$ gem install email_template
Run installer:
$ rails g email_template:install
In order to use Devise templates you need to install devise wrapper:
$ rails g email_template:devise_install
Then generate common devise templates for a specified scope:
$ rails g email_template:devise_templates <devise_scope>
This generator produces email templates with the names:
<devise_scope>_mailer:confirmation_instructions
<devise_scope>_mailer:reset_password_instructions
<devise_scope>_mailer:unlock_instructions
Run:
$ rake db:migrate
You can configure email_template at
config/initializers/email_template.rb
Pull template to the base :
MailTemplate.create(name: "activity_partner_mailer:join_confirmation_self",
subject: "Join request confirmation",
classes: ["activity_partner"],
body:
<<-TEXT
Dear \#{activity_partner.full_name} ...
....
TEXT
)
In Mailer:
class ActivityPartnerMailer < TemplateSendMailer
def join_confirmation_self(activity_partner)
#send_mail(template_name, mail_params = {}, template_params = {})
send_mail("#{self.class.name.tableize.singularize}:#{__method__}", {to: "user@example.com"}, {activity_partner_join: activity_partner})
end
end
In case you need additional customization :
In Mailer:
class CustomDeviseMailer < Devise::Mailer
include Devise::Mailers::Helpers
include EmailTemplate::Mailers::Helpers
def confirmation_instructions(record, opts={})
@template = check_template("#{record.class.name.tableize.singularize}_mailer:#{__method__}")
devise_mail(record, :confirmation_instructions, opts.merge(subject: @template.subject))
end
end
In View:
= raw(@template.as_html(:parent => @resource).gsub(/\#\{confirm_link\}/,
link_to('Confirm my account', confirmation_url(@resource, confirmation_token: @resource.confirmation_token))))
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Added some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request