ruby - Send user email 24 hours after inactivity, rails -


basically, want send email reminder user if haven't made posts within 24 hours of being created. confused on how send email without first making action, such 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 on site!') end 

you don't need happen via controller action, need cron job fire off task (the whenever gem this). might like:

every 1.day, :at => '4:30 am'   runner "user.notify_lazy_users" end 

Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -