写了一个rails的email通知脚本

<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
当使用Rails框架编接口时,可以按照以下步骤进行: 1. 创建一个新的Rails应用程序: 打开终端,导航到项目目录并运行以下命令: ``` rails new api_example cd api_example ``` 2. 创建一个控制器: 运行以下命令创建一个控制器: ``` rails generate controller Api ``` 3. 在控制器中定义接口方法: 打开 `app/controllers/api_controller.rb` 文件,添加如下方法: ```ruby class ApiController < ApplicationController def hello render json: { message: 'Hello, World!' } end def greet name = params[:name] render json: { message: "Hello, #{name}!" } end end ``` 4. 配置路由: 打开 `config/routes.rb` 文件,添加以下路由配置: ```ruby Rails.application.routes.draw do get '/api/hello', to: 'api#hello' post '/api/greet', to: 'api#greet' end ``` 5. 运行应用程序: 在终端中运行以下命令启动Rails服务器: ``` rails server ``` 现在,你的Rails应用程序就有了两个接口:`/api/hello` 和 `/api/greet`。 - GET请求的 `/api/hello` 接口返回一个JSON响应,包含一条简单的问候消息。 - POST请求的 `/api/greet` 接口从请求参数中获取名字,并返回一个包含问候消息的JSON响应。 你可以使用REST客户端(如Postman)或浏览器来访问这些接口,例如: - GET请求:`http://localhost:3000/api/hello` - POST请求:`http://localhost:3000/api/greet`,并在请求体中添加名为`name`的参数。 这样,你就可以使用Rails框架创建一个简单的接口,处理不同的HTTP请求并返回相应的JSON响应。当然,在实际开发中,可能会涉及更复杂的数据处理和业务逻辑,但这个例子可以帮助你快速入门。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值