Skip to content

Instantly share code, notes, and snippets.

@walidvb
Last active August 29, 2015 14:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save walidvb/4f0968f6cae5743b67f7 to your computer and use it in GitHub Desktop.
Save walidvb/4f0968f6cae5743b67f7 to your computer and use it in GitHub Desktop.
Allow admin to edit emails sent by Devise
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
Devise.setup do |config|
config.mailer = 'CustomDeviseMailer'
end
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
- 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