diff --git a/app/models/application_record.rb b/app/models/application_record.rb index f19cacf409241c3e97f4c4b2a38db2c9c6c2dc7f..fc247cf5201df486db8442e6e3559b16c411b1a1 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 e48b1a7b616a033185df24fa8017d3928f45b618..122cad79864835a4ca02e3a2abd203d7d9f56ff3 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',