<meta http-equiv="Content-Type" content="text/html; charset=unicode"> <meta name="Generator" content="Microsoft SafeHTML">
1 ENV["RAILS_ENV"] = "development"
2 require File.expand_path(File.dirname(__FILE__) + "/config/environment")
3
4 list = Notification.find(:all,:select=>'note,author,uid',:group=>'uid',:conditions=>'new=1' )
5 for i in list
6 # MyMailer.deliver_send i.note
7 email = Notification.find_by_sql('select email from ucenter.uc_members where uid='+i.ui d.to_s)
8 email = email[0].email
9
10 notes = Notification.find(:all,:select=>'note,author',:conditions=>['new=1 and uid=?',i .uid])
11 notes=notes[0,5]
12 text = notes.inject(''){|text,j|text+j.author+j.note+"\r\n"}
13 text = text.gsub(/href="/,'href="http://10.11.28.99/sns/')
14 puts 'start:'+email
15 MyMailer.deliver_send text,email
16 end
要在ucenter上做一个类似豆瓣提醒email的小功能。。。我直接用rails做
用script/generate mailer mymailer send 生产mail模型,然后写发送脚本。。。
脚本逻辑是:查找有新消息的人->跨库查询email->把新消息聚合起来->发送邮件
ror核心代码16行代码就搞定。。。ror果然是为web2.0开发特别定做的...迅速,表现力强,修改方便
而ucenter的代码好长好繁冗。。。需要极大的精力和水平来读懂
2008-06-10
chenjinlai