-
Notifications
You must be signed in to change notification settings - Fork 0
/
ticket.rb
40 lines (33 loc) · 1.05 KB
/
ticket.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# == Schema Information
#
# Table name: tickets
#
# id :integer not null, primary key
# ticket_group_id :integer
# creator_id :integer
# owner_id :integer
# name :string(255)
# description :text
# status :string(255)
# due_date :datetime
# comment_count :integer
# created_at :datetime
# updated_at :datetime
#
class Ticket < ActiveRecord::Base
belongs_to :ticket_group, :counter_cache => true
belongs_to :creator, :class_name => 'User'
belongs_to :assignee, :foreign_key => "owner_id", :class_name => "User"
has_many :comments
before_create :set_default_status
validates :name, :presence => true
validates :ticket_group_id, :presence => {:message => "Ticket must be assign to a Ticket Group"}
#validates :owner_id, :presence => {:message => "You must assign a ticket to a user"}
STATUSES = ['open', 'closed', 'pending']
def set_default_status
self.status = 'open'
end
def default_email_recipients(user = nil)
ticket_group.users - [user]
end
end