Reputation: 345
Basically, I want to send an email reminder to a User if they haven't made any posts within 24 hours of being created. I am confused on how to send an email without first making an action, such as create
or update
.
controller users_controller.rb
def run
@user = current_user
if Time.now.utc == @user.created_at + 24.hours && @user.microposts.empty?
UserMailer.twentyfour_email(@user).deliver
end
end
mailer user_mailer.rb
def twentyfour_mailer
@user = user
mail(to: @user.email, subject: 'Post something on the site!')
end
Upvotes: 0
Views: 681
Reputation: 373
Make it easy.
You can use Delayed Job for instance.
UserMailer.twentyfour_mailer.delay(run_at: 24.hours.from_now)
Upvotes: 0