我需要为 :assign_state 和 :state_closed 运行回调,但它们不起作用并引发
Stack level to deep
票务.rb
class Ticket < ActiveRecord::Base
before_save :default_values
after_update :state_closed
after_create :assign_state
attr_accessible :description, :title, :employee_department_id, :user_id, :first_name,
:last_name , :email, :state_id, :employee_id, :ticket_state, :assign_state
belongs_to :employee_department
belongs_to :user
belongs_to :state
belongs_to :employee
has_many :replies
def default_values
self.state_id = 3 if self.state_id.nil?
end
def to_label
ticket_state.to_s
end
def state_closed
if self.ticket_state == "Solved" || self.ticket_state == "Canceled"
self.ticket_state = "Closed"
self.save
end
end
def assign_state
if self.employee_id.nil?
self.assign_state = "Un-assigned"
else
self.assign_state = "Assigned"
end
self.save
end
Ticket.all.each do |ticket|
if ticket.ticket_state.blank?
ticket.ticket_state = 'open'
end
ticket.save
end
end