From 5eaa2941ad36a754fbf77e8df7b61a9298afe52f Mon Sep 17 00:00:00 2001 From: Xavier J Date: Mon, 26 Dec 2016 11:08:53 +0100 Subject: [PATCH] Move commentaire creation to model --- app/controllers/commentaires_controller.rb | 2 -- app/models/commentaire.rb | 8 ++++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/app/controllers/commentaires_controller.rb b/app/controllers/commentaires_controller.rb index a3cb762f5..cdf3cb747 100644 --- a/app/controllers/commentaires_controller.rb +++ b/app/controllers/commentaires_controller.rb @@ -51,8 +51,6 @@ class CommentairesController < ApplicationController redirect_to url_for(controller: 'backoffice/dossiers', action: :show, id: params['dossier_id']) else - NotificationService.new('commentaire', @commentaire.dossier.id).notify if saved - if current_user.email != @commentaire.dossier.user.email invite = Invite.where(dossier: @commentaire.dossier, user: current_user).first redirect_to url_for(controller: 'users/dossiers/invites', action: :show, id: invite.id) diff --git a/app/models/commentaire.rb b/app/models/commentaire.rb index 463285482..2a785da37 100644 --- a/app/models/commentaire.rb +++ b/app/models/commentaire.rb @@ -4,7 +4,15 @@ class Commentaire < ActiveRecord::Base belongs_to :piece_justificative + after_save :internal_notification + def header "#{email}, " + created_at.localtime.strftime('%d %b %Y %H:%M') end + + private + + def internal_notification + NotificationService.new('commentaire', self.dossier.id).notify + end end