こんにちは、プロジェクトがあり、各プロジェクトにはタスクがあります。タスクはプロジェクトに属します。プロジェクトを削除する前に、関連するタスクがあるかどうかを確認したいと考えています。プロジェクトを削除したくないタスクがある場合。関連するタスクがない場合は、プロジェクトを削除する必要があります。コードを教えてください。私は何が欠けていますか?
class Project < ActiveRecord::Base
before_destroy :check_tasks
def check_tasks
if Project.find(params[:id]).tasks
flash[:notice] = 'This project has tasks.'
redirect_to :action => 'list_projects'
end
end
end