Statuses in task - db field and forms

This commit is contained in:
2025-10-25 17:41:06 +03:00
parent b08468568b
commit ba2aad93af
12 changed files with 86 additions and 13 deletions
+10
View File
@@ -2,9 +2,11 @@
class Task < ApplicationRecord
belongs_to :project
belongs_to :status, class_name: 'TaskStatus'
validates :number, :title, presence: true
validates :number, numericality: { greater_than: 0 }
validate :associations_should_have_same_project
has_rich_text :description
@@ -25,4 +27,12 @@ class Task < ApplicationRecord
project = Project.find_by!(code: project_code.downcase)
find_by!(project:, number:)
end
private
def associations_should_have_same_project
return if status&.project == project
errors.add(:status, "Doesn't belong in the same project")
end
end
+2
View File
@@ -7,4 +7,6 @@ class TaskStatus < ApplicationRecord
validates :name, presence: true, uniqueness: { scope: :project }
validates :category, presence: true
scope :default_order, -> { order(:category, :name) }
end