#4 Move Find into Model

#tasks_controller.rb
def index
  @tasks = Task.find_incomplete
end

#--------------------------------

#models/task.rb
def self.find_incomplete
  find_all_by_complete(false, :order => 'created_at DESC')
end

#--------------------------------

#projects_controller.rb
def show
  @project = Project.find(params[:id])
  @tasks = @project.tasks.find_incomplete
end

你可能感兴趣的:(Ruby,Rails)