diff --git a/app/models/budget.rb b/app/models/budget.rb index bf64c0fd6..56b774a41 100644 --- a/app/models/budget.rb +++ b/app/models/budget.rb @@ -14,6 +14,7 @@ class Budget < ActiveRecord::Base has_many :ballots, dependent: :destroy has_many :groups, dependent: :destroy has_many :headings, through: :groups + has_many :phases, class_name: Budget::Phase before_validation :sanitize_descriptions @@ -26,15 +27,22 @@ class Budget < ActiveRecord::Base scope :balloting, -> { where(phase: "balloting") } scope :reviewing_ballots, -> { where(phase: "reviewing_ballots") } scope :finished, -> { where(phase: "finished") } - scope :current, -> { where.not(phase: "finished") } + def current_phase + phases.send(phase) + end + def description description_for_phase(phase) end def description_for_phase(phase) - send("description_#{phase}").try(:html_safe) + if phases.exists? && phases.send(phase).description.present? + phases.send(phase).description + else + send("description_#{phase}").try(:html_safe) + end end def self.title_max_length