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) |