写了一个rails的email通知脚本

本文介绍了一个使用Ruby on Rails实现的邮件通知功能。该功能通过查找有新消息的用户、跨库查询用户的电子邮件地址、聚合新消息并发送邮件。整个过程仅需16行核心代码即可完成。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

<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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值