parent
b927ab4568
commit
a08f170dbd
11 changed files with 39 additions and 25 deletions
|
@ -1,16 +1,18 @@
|
|||
class CommentaireService
|
||||
class << self
|
||||
def create(sender, dossier, params)
|
||||
attributes = params.merge(email: sender.email, dossier: dossier)
|
||||
|
||||
# If the user submits a empty message, simple_format will replace '' by '<p></p>',
|
||||
# and thus bypass the not-empty constraint on commentaire's body.
|
||||
#
|
||||
# To avoid this, format the message only if a body is present in the first place.
|
||||
if attributes[:body].present?
|
||||
attributes[:body] = ActionController::Base.helpers.simple_format(attributes[:body])
|
||||
def build(sender, dossier, params)
|
||||
case sender
|
||||
when User
|
||||
params[:user] = sender
|
||||
when Gestionnaire
|
||||
params[:gestionnaire] = sender
|
||||
end
|
||||
|
||||
build_with_email(sender.email, dossier, params)
|
||||
end
|
||||
|
||||
def build_with_email(email, dossier, params)
|
||||
attributes = params.merge(email: email, dossier: dossier)
|
||||
Commentaire.new(attributes)
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue