如何根据用户在 Rails 中输入的日期,每周继续向用户发送电子邮件
新的导轨和现在使用窗口,,我有用户插入姓名、日期和电子邮件的网页.根据他的日期输入,我想给他发送电子邮件(如果 @dop.date=date.now-7.days 然后发送电子邮件
).我怎么能实现呢??我希望系统获取用户日期并检查它是否用户插入日期,并且日期已经 7 天,然后给他发送电子邮件...
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
这是我的模型:等级 Dop <ActiveRecord::Baseattr_accessible :date,:mail,:namevalidates_presence_of:namevalidates_presence_of:mailvalidates_uniqueness_of:mail
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
结束
使用 cron 安排重复的 rake 任务.如果您使用 heroku,则可以将 cron 作为附加组件使用.但首先,当然,您需要编写 rake 任务——用于提示:
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
长短 - rake 是一个文件,它允许您定义各种任务并在这些任务之间建立依赖关系.它非常适合管理/清理工具,或者,就您而言,是应用程序实际执行之外的工具.
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.