2012年11月20日
摘要: 这次,我们讨论一下with_scope方法。下面的Task中定义了一个返回所有未完成任务的类方法find_incomplete。 class Task < ActiveRecord::Base belongs_to :project def self.find_incomplete find_all_by_complete(false, :order => 'created_at DE... 阅读全文
posted @ 2012-11-20 22:09 边晓宇 阅读(992) 评论(0) 推荐(1) 编辑
摘要: 这个例子是对Task调用find命令进行查询操作,查询所有未完成的任务并按照创建时间降序排列。如下所示: class TaskController < ApplicationController def index @tasks = Task.find_all_by_complete(:false, :order => "created_at DESC") endend如果控制器中有好... 阅读全文
posted @ 2012-11-20 07:51 边晓宇 阅读(985) 评论(0) 推荐(1) 编辑