gestionnaire: move commentaire creation into a service
This commit is contained in:
parent
d31cc04b23
commit
750e1e0c83
4 changed files with 79 additions and 34 deletions
17
app/services/commentaire_service.rb
Normal file
17
app/services/commentaire_service.rb
Normal file
|
@ -0,0 +1,17 @@
|
|||
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])
|
||||
end
|
||||
|
||||
Commentaire.new(attributes)
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue