原创作者: hideto
阅读:1384次
评论:0条
更新时间:2011-05-26
沿着Rails宝典之第三式: 通过关联做查询的脚步,我们可以进一步简化代码:
class Task < ActiveRecord::Base belongs_to :project def self.find_incomplete find_all_by_complete(false, : order => 'created_at DESC') end end class ProjectsController < ApplicationController def show @project = Project.find(param[:id]) @tasks = @project.tasks.find_incomplete end end class TasksController < ApplicationController def index @tasks = Task.find_incomplete end end
评论 共 0 条 请登录后发表评论