#3 Find Through Association

#project has_many tasks 

def show
  @project = Project.find(params[:id])
  @tasks = Task.find(:all, :conditions => ["project_id = ? AND complete = ?", @project.id, false])
end

#优化

def show
  @project = Project.find(params[:id])
  @tasks = @project.tasks.find_all_by_complete(false)
end

你可能感兴趣的:(#3 Find Through Association)