Project has_many Tasks
Task belongs_to Project
传统做法:
@project = Project.find(params[:id])Rails做法:
@tasks = Task.find(:all, :conditions => ['project_id = ? AND complete = ?'], @project.id, false)
@tasks = @project.tasks.find(:all, :conditions => ['complete = ?'], false)用episode 002介绍的动态方法进一步简化:
@tasks = @project.tasks.find_all_by_complete(false)
没有评论:
发表评论