如何继续每周向用户发送电子邮件,具体取决于在rails中输入的用户日期

新的铁路和现在使用Windows,我有网页,用户插入名称,日期和电子邮件。 根据他的日期输入我想给他发电子邮件(如果@dop.date=date.now-7.days then send email )。 我怎么能实现它? 我希望系统获取用户日期并检查用户是否插入日期,日期为7天,然后向他发送电子邮件…


 class UserMailer  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 

这是我的模型:类Dop <ActiveRecord :: Base attr_accessible:date,:mail,:name validates_presence_of:name validates_presence_of:mail validates_uniqueness_of:mail

结束


使用cron来安排重复的rake任务。 如果您正在使用heroku,则可以将cron作为附加组件。 但首先,当然,您需要编写rake任务 – 以获取提示:

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

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

Long和short-rake是一个文件,允许您定义各种任务并在这些任务之间建立依赖关系。 它非常适合管理/清理工具,或者在您的情况下,是实际执行应用程序之外的东西。