Class: ArticlePage

Inherits:
ApplicationRecord show all
Includes:
Models::Auditable
Defined in:
app/models/article_page.rb

Overview

== Schema Information

Table name: article_pages
Database name: primary

id :bigint not null, primary key
content :text not null
headline :text
position :integer not null
created_at :datetime not null
updated_at :datetime not null
article_id :integer not null

Indexes

index_article_pages_on_article_id_and_position (article_id,position) UNIQUE

Foreign Keys

fk_rails_... (article_id => articles.id) ON DELETE => cascade

Constant Summary

Constants included from Models::Auditable

Models::Auditable::ALWAYS_IGNORED

Constants included from Models::Schedulable

Models::Schedulable::SIMPLE_FORM_OPTIONS

Instance Attribute Summary collapse

Belongs to collapse

Methods included from Models::Auditable

#creator, #updater

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Models::Auditable

#all_skipped_columns, #audit_reference_data, #should_not_save_version, #stamp_record

Methods inherited from ApplicationRecord

ransackable_associations, ransackable_attributes, ransackable_scopes, ransortable_attributes, #to_relation

Methods included from Models::Schedulable

config

Methods included from Models::AfterCommittable

#after_commit

Methods included from Models::EventPublishable

#publish_event

Instance Attribute Details

#contentString

Returns:

  • (String)


31
# File 'app/models/article_page.rb', line 31

validates :content, presence: true

Class Method Details

.sortedActiveRecord::Relation<ArticlePage>

A relation of ArticlePages that are sorted. Active Record Scope

Returns:

See Also:



39
# File 'app/models/article_page.rb', line 39

scope :sorted, -> { order(:position) }

Instance Method Details

#articleArticle

Returns:



27
# File 'app/models/article_page.rb', line 27

belongs_to :article

#localized_content(locale = nil) ⇒ String?

Any localized links in the article content will be prepended with the right locale.

Parameters:

  • locale (Symbol, String, nil) (defaults to: nil)

Returns:

  • (String, nil)


44
45
46
47
48
49
# File 'app/models/article_page.rb', line 44

def localized_content(locale = nil)
  return if content.blank?

  locale ||= I18n.locale
  content.gsub(/\{\{\s*locale\s*\}\}/, locale.to_s)
end

#localized_content_html_docNokogiri::HTML::Document

Returns:

  • (Nokogiri::HTML::Document)


52
53
54
# File 'app/models/article_page.rb', line 52

def localized_content_html_doc
  Nokogiri::HTML(localized_content)
end