두 모델 티켓 및 TicketComment의 TicketComment는 Ticket의 하위 항목입니다.레일은 콜백에 _nested_attributes_을 허용합니다.
ticket.rb
class Ticket < ActiveRecord::Base
has_many :ticket_comments, :dependent => :destroy, :order => 'created_at DESC'
# allow the ticket comments to be created from within a ticket form
accepts_nested_attributes_for :ticket_comments, :reject_if => proc { |attributes| attributes['comment'].blank? }
end
ticket_comment.rb
class TicketComment < ActiveRecord::Base
belongs_to :ticket
validates_presence_of :comment
end
내가하고 싶은 것은 어디 경우 Trac에,의 기능을 모방하다 에이 사용자가 티켓을 변경하거나 설명을 추가하면 티켓에 지정된 사람에게 전자 메일이 전송됩니다.
전자 메일을 보내기 전에 정보가 모두 저장되었음을 알 수 있도록 after_update 또는 after_save 콜백을 사용하고 싶습니다.
모델 (ticket.changes)의 변경 사항과 새 메모가 작성되었는지 (ticket.comments),이 업데이트를 보낼지 (x 변경 사항은 y, 사용자는 '텍스트 추가'사용자 의견) 어떻게 감지 할 수 있습니까? 하나의 이메일에 콜백 메소드를 사용 하시겠습니까?
아하, 질문을 잘못 해석 한 것 같습니다. 사과. 나는 실제 해결책을 제시하려고 노력할 것이다. –