Skip to content
Snippets Groups Projects
Commit 8e8dab46 authored by Arnaud Levy's avatar Arnaud Levy
Browse files

better

parent 44f9efaa
No related branches found
No related tags found
No related merge requests found
class ApplicationRecord < ActiveRecord::Base
self.abstract_class = true
# Remove everything below after migration, please
def self.summernote(*args)
@@summernote_fields = args
end
before_validation :summernote
def summernote
@@summernote_fields.each do |field|
self["#{field}_new"] = send(field).to_s
.gsub('<div>', '<p>')
.gsub('</div>', '</p>')
.gsub('<p><br></p>', '')
end
end
end
......@@ -40,6 +40,8 @@ class Communication::Website::Post < ApplicationRecord
has_rich_text :text
summernote :text
has_one :imported_post,
class_name: 'Communication::Website::Imported::Post',
dependent: :destroy
......@@ -60,8 +62,6 @@ class Communication::Website::Post < ApplicationRecord
before_validation :set_published_at, if: :published_changed?
before_validation :summernote
scope :published, -> { where(published: true) }
scope :ordered, -> { order(published_at: :desc, created_at: :desc) }
scope :recent, -> { order(published_at: :desc).limit(5) }
......@@ -107,8 +107,4 @@ class Communication::Website::Post < ApplicationRecord
def inherited_blob_ids
[best_featured_image&.blob_id]
end
def summernote
self.text_new = self.text.to_s.gsub('<div>', '<p>').gsub('</div>', '</p>').gsub('<p><br></p>', '')
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment