Chinaunix首页 | 论坛 | 博客
  • 博客访问: 41617
  • 博文数量: 27
  • 博客积分: 2010
  • 博客等级: 大尉
  • 技术积分: 300
  • 用 户 组: 普通用户
  • 注册时间: 2006-10-24 00:44
文章分类
文章存档

2011年(1)

2009年(26)

我的朋友
最近访客

分类: Java

2009-04-17 12:55:05

class TaskController < ApplicationController
    def incomplete
       @tasks = Task.find(:all, :conditions => ["complete = ?", false])
    end


    def last_incomplete
       @task = Task.find(:first, :conditions => ['complete = ?', false], :order =>             "create_at DESC")
    end
end

in rails, there is a better way to implement the above functions:


class TaskController < ApplicationController
    def incomplete
       @tasks = Task.find_all_by_complete(false)
    end


    def last_incomplete
       @task = Task.find_by_complete(false, :order => 'create_at DESC')
    end
end

It is more readable and more precise.

阅读(346) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~