From 0aec20767d9e5de416f1b8fd2a729a75cdadc7c7 Mon Sep 17 00:00:00 2001
From: Arnaud Levy <contact@arnaudlevy.com>
Date: Thu, 10 Feb 2022 16:52:37 +0100
Subject: [PATCH] simple, but not working fully

---
 app/models/application_record.rb         | 15 ++++++++-------
 app/models/communication/website/post.rb |  2 +-
 2 files changed, 9 insertions(+), 8 deletions(-)

diff --git a/app/models/application_record.rb b/app/models/application_record.rb
index f19cacf40..fc247cf52 100644
--- a/app/models/application_record.rb
+++ b/app/models/application_record.rb
@@ -7,26 +7,27 @@ class ApplicationRecord < ActiveRecord::Base
   def self.has_summernote(name)
     class_eval <<-CODE, __FILE__, __LINE__ + 1
       def #{name}
-        # TODO hydrate action-text-attachment
-        attributes['#{name}'].gsub('</action', 'coucou</action')
+        value = attributes['#{name}']
+        actiontext = ActionText::Content.new value
+        actiontext.to_s
       end
 
       def #{name}=(value)
-        # TODO dehydrate action-text-attachment
-        attributes['#{name}'] = value
+        actiontext = ActionText::Content.new value
+        self.attributes['#{name}'] = actiontext.to_html
       end
     CODE
   end
 
   # TODO Remove everything below after migration, please
 
-  def self.summernote(*args)
+  def self.convert_fields_to_summernote(*args)
     @@summernote_fields = args
   end
 
-  before_validation :summernote
+  # before_validation :convert_to_summernote
 
-  def summernote
+  def convert_to_summernote
     @@summernote_fields.each do |field|
       self["#{field}_new"] = send(field).body.to_html
                                         .gsub('<div>', '<p>')
diff --git a/app/models/communication/website/post.rb b/app/models/communication/website/post.rb
index e48b1a7b6..122cad798 100644
--- a/app/models/communication/website/post.rb
+++ b/app/models/communication/website/post.rb
@@ -41,7 +41,7 @@ class Communication::Website::Post < ApplicationRecord
   has_rich_text :text
   has_summernote :text_new
 
-  summernote :text
+  convert_fields_to_summernote :text
 
   has_one :imported_post,
           class_name: 'Communication::Website::Imported::Post',
-- 
GitLab