Created
June 5, 2014 16:24
-
-
Save mikeadeleke/59519ca92f702a188394 to your computer and use it in GitHub Desktop.
Rake tasks, automated emails, and whenever gem
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
email_reminders.rake | |
namespace :email_reminders do | |
desc "reminds the user to complete their profile" | |
task :founder_welcome => :environment do | |
if Rails.env == "production" | |
if @user.profile.present? | |
ConfirmMailer.founder_welcome(@user).deliver | |
end | |
end | |
end | |
end | |
namespace :email_reminders do | |
desc "reminds a user to click the confirm link in their confirm email" | |
task :confirm_email => :environment do | |
if Rails.env == "production" | |
users = User.where(‚confirmation_token IS NOT NULL‘) | |
if users | |
@user = user | |
users.each do |user| | |
ConfirmMailer.user_confirmation(@user).deliver | |
end | |
end | |
end | |
end | |
end | |
namespace :email_reminders do | |
desc "reminds the user to complete their profile" | |
task :make_profile => :environment do | |
if Rails.env == "production" | |
if @user.profile.nil? | |
ConfirmMailer.create_profile(@user).deliver | |
end | |
end | |
end | |
end | |
namespace :email_reminders do | |
desc "reminds the user to list their property" | |
task :list_property => :environment do | |
if Rails.env == "production" | |
if @user.properties.present? && @user.listings.empty? | |
ConfirmMailer.list_property(@user).deliver | |
end | |
end | |
end | |
end | |
namespace :email_reminders do | |
desc "reminds a user to invite their roommates" | |
task :invite_roommates => :environment do | |
if Rails.env == "production" | |
if @user.listings.present? | |
ConfirmMailer.invite_roommates(@user).deliver | |
end | |
end | |
end | |
end | |
confirm_mailer.rb | |
class ConfirmMailer < ActionMailer::Base | |
default from: "mike@trydomi.com" | |
def founder_welcome(user) | |
@user = user | |
@url = 'https://www.trydomi.com' | |
mail(to: @user.email, subject: 'Welcome to Domi!') | |
end | |
def user_confirmation(user) | |
@user = user | |
mail(to: @user.email, subject: 'Confirm your account to join Domi!') | |
end | |
def create_profile(user) | |
@user = user | |
@url = 'https://www.trydomi.com/profiles/new' | |
mail(to: @user.email, subject: 'Get started with Domi! Create your profile!') | |
end | |
def list_property(user) | |
@user = user | |
@url = 'https://www.trydomi.com/listings/new' | |
mail(to: @user.email, subject: 'Get your place sublet and list!') | |
end | |
def invite_roommates(user) | |
@user = user | |
@url = @user.listings.last | |
mail(to: @user.email, subject: 'Listings with roommates are more likely to sublet!') | |
end | |
end | |
schedule.rb | |
# Use this file to easily define all of your cron jobs. | |
# | |
# It's helpful, but not entirely necessary to understand cron before proceeding. | |
# http://en.wikipedia.org/wiki/Cron | |
# Example: | |
# | |
# set :output, "/path/to/my/cron_log.log" | |
# | |
# every 2.hours do | |
# command "/usr/bin/some_great_command" | |
# runner "MyModel.some_method" | |
# rake "some:great:rake:task" | |
# end | |
# | |
# every 4.days do | |
# runner "AnotherModel.prune_old_records" | |
# end | |
# Learn more: http://github.com/javan/whenever | |
Gemfile | |
.......... | |
gem "whenever" | |
.......... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment