Last active
August 29, 2015 14:12
-
-
Save walidvb/4f0968f6cae5743b67f7 to your computer and use it in GitHub Desktop.
Allow admin to edit emails sent by Devise
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CustomDeviseMailer < Devise::Mailer | |
def self.deliver_welcome_email(user) | |
self.welcome_email(user) | |
end | |
def welcome_email(user) | |
@user = user | |
# if the email's ID is 1 | |
@welcome_email = Email.find_by_id(1) | |
mail(to: @user.email, subject: "Welcome to The Pigeonhole!") | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Devise.setup do |config| | |
config.mailer = 'CustomDeviseMailer' | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Email < ActiveRecord::Base | |
before_destroy :verify_indestructible | |
validates_presence_of :title, :body | |
private | |
def verify_indestructible | |
if indestructible? | |
self.errors[:base] << "Cannot destroy this email." | |
return false | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- if !@welcome_email.nil? && @welcome_email.active? | |
= @welcome_email.body.html_safe | |
- else | |
%p Your default welcome email |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment