how to keep sending emails to users every week depending on user date input in rails [closed]

耗尽温柔 提交于 2019-12-31 07:41:21

问题


new on rails and using windows for now,, i have web page that user insert name, date and email. depending on his date input i want to send him email(if @dop.date=date.now-7.days then send email ). how could i implement it?? i want the system get user dates and check it if user insert date, and the date has been for 7 days then send him email...


class UserMailer < ActionMailer::Base
  default from: "from@example.com"

  def welcome_email(dop)
    @dop = dop
    @url  = "http://example.com/login"
    mail(:to => dop.mail, :subject => "Welcome to My Awesome Site")
  end
end

 def create
    @dop = Dop.new(params[:dop])

    respond_to do |format|
      if @dop.save
        UserMailer.welcome_email(@dop).deliver
        format.html { redirect_to @dop, notice: 'Dop was successfully created.' }
        format.json { render json: @dop, status: :created, location: @dop }
      else
        format.html { render action: "new" }
        format.json { render json: @dop.errors, status: :unprocessable_entity }
      end
    end
  end

here is my model: class Dop < ActiveRecord::Base attr_accessible :date,:mail,:name validates_presence_of:name validates_presence_of:mail validates_uniqueness_of:mail

end



回答1:


Use cron to schedule a repeating rake task. If you're using heroku, you can get cron as an add-on. But first, of course, you need to write the rake task -- for tips:

http://railscasts.com/episodes/66-custom-rake-tasks/

http://jasonseifer.com/2010/04/06/rake-tutorial

Long and the short - rake is a file that allows you to define various tasks and establish dependencies among those tasks. It's perfect for administrative/cleanup tools, or, in your case, something outside the actual execution of your application.



来源:https://stackoverflow.com/questions/11205195/how-to-keep-sending-emails-to-users-every-week-depending-on-user-date-input-in-r

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!