1require_dependency 'archived' |
|
3module Archived |
|
4 class GovernmentResponse < ActiveRecord::Base |
|
5 belongs_to :petition, touch: true |
|
7 validates :petition, presence: true |
|
8 validates :summary, presence: true, length: { maximum: 500 } |
|
9 validates :details, length: { maximum: 10000 }, allow_blank: true |
|
10 validates :responded_on, presence: true |
|
12 after_create do |
|
13 petition.touch(:government_response_at) unless petition.government_response_at? |
|
14 end |
|
16 def responded_on |
|
17 super || default_responded_on |
|
18 end |
|
20 private
|
|
22 def default_responded_on |
|
23 if petition && petition.government_response_at |
|
24 petition.government_response_at.to_date
|
|
25 elsif created_at |
|
26 created_at.to_date
|
|
27 end |
|
28 end |
|
29 end |
|
30end |