Class: Faq

Inherits:
ApplicationRecord show all
Includes:
PgSearch::Model
Defined in:
app/models/faq.rb

Overview

Faq is model responsible for storing faq informations.

Relations

  • acts_as_taggable_on :categories

  • has_rich_text :content

  • has_many_attached :files

  • has_many_attached :instructions

  • has_many_attached :models

  • has_many :favorites, class_name: ‘UserFaq’, inverse_of: :faq

  • has_many :users, through: :favorites, source: :user

Validations

  • validate presence of #title

  • validate presence of #content

  • validate presence of categories

Instance Attribute Summary collapse

Instance Attribute Details

#activeBoolean

Returns if Faq is active.

Returns:

  • (Boolean)

    if Faq is active



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'app/models/faq.rb', line 44

class Faq < ApplicationRecord
  include PgSearch::Model
  acts_as_taggable_on :categories
  has_rich_text :content
  has_many_attached :files
  has_many_attached :instructions
  has_many_attached :models
  has_many :favorites, class_name: 'UserFaq', inverse_of: :faq
  has_many :users, through: :favorites, source: :user

  enum visibility: Settings.faq.visibility.to_hash

  store_accessor :metadata, :created_by, :updated_by, :approved_by

  scope :actived, -> { where(active: true) }
  scope :unactived, -> { where(active: false) }
  scope :approved, -> { where(approve: true) }
  scope :unapproved, -> { where(approve: false) }
  scope :evidenced, -> { where(evidence: true) }
  scope :on_top, ->(top = Settings.faq.top) { actived.approved.where("counter >= ?", 1).order(counter: :desc).limit(top) }
  pg_search_scope :search_by_title,
                    against: :title,
                    ignoring: :accents,
                    using: {
                      tsearch: { prefix: true, normalization: 2, any_word: true },
                      trigram: { threshold: 0.5, word_similarity: true },
                      dmetaphone: {}
                    },
                    order_within_rank: "faqs.counter DESC"

  before_validation :prerequisite
  validates :title, presence: true, uniqueness: true
  # validates :content, presence: true
  validates :structure, presence: true
  validates :visibility, presence: true
  validates_inclusion_of :visibility, in: visibilities.keys,
                                      message: "state must be one of #{visibilities.keys}"
  validate :must_have_valid_categories

  private

  def prerequisite
    self.created_by ||= Settings.system.username if created_by.blank? && new_record?
    self.updated_by ||= Settings.system.username
  end

  def must_have_valid_categories
    errors.add(:category_list, I18n.t('is_required', scope: '', default: "is required!")) if category_list.blank? && !Rails.env.test?
  end

end

#approveBoolean

Returns if Faq is approved.

Returns:

  • (Boolean)

    if Faq is approved



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'app/models/faq.rb', line 44

class Faq < ApplicationRecord
  include PgSearch::Model
  acts_as_taggable_on :categories
  has_rich_text :content
  has_many_attached :files
  has_many_attached :instructions
  has_many_attached :models
  has_many :favorites, class_name: 'UserFaq', inverse_of: :faq
  has_many :users, through: :favorites, source: :user

  enum visibility: Settings.faq.visibility.to_hash

  store_accessor :metadata, :created_by, :updated_by, :approved_by

  scope :actived, -> { where(active: true) }
  scope :unactived, -> { where(active: false) }
  scope :approved, -> { where(approve: true) }
  scope :unapproved, -> { where(approve: false) }
  scope :evidenced, -> { where(evidence: true) }
  scope :on_top, ->(top = Settings.faq.top) { actived.approved.where("counter >= ?", 1).order(counter: :desc).limit(top) }
  pg_search_scope :search_by_title,
                    against: :title,
                    ignoring: :accents,
                    using: {
                      tsearch: { prefix: true, normalization: 2, any_word: true },
                      trigram: { threshold: 0.5, word_similarity: true },
                      dmetaphone: {}
                    },
                    order_within_rank: "faqs.counter DESC"

  before_validation :prerequisite
  validates :title, presence: true, uniqueness: true
  # validates :content, presence: true
  validates :structure, presence: true
  validates :visibility, presence: true
  validates_inclusion_of :visibility, in: visibilities.keys,
                                      message: "state must be one of #{visibilities.keys}"
  validate :must_have_valid_categories

  private

  def prerequisite
    self.created_by ||= Settings.system.username if created_by.blank? && new_record?
    self.updated_by ||= Settings.system.username
  end

  def must_have_valid_categories
    errors.add(:category_list, I18n.t('is_required', scope: '', default: "is required!")) if category_list.blank? && !Rails.env.test?
  end

end

#contentRich Text

Returns content of Faq.

Returns:

  • (Rich Text)

    content of Faq



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'app/models/faq.rb', line 44

class Faq < ApplicationRecord
  include PgSearch::Model
  acts_as_taggable_on :categories
  has_rich_text :content
  has_many_attached :files
  has_many_attached :instructions
  has_many_attached :models
  has_many :favorites, class_name: 'UserFaq', inverse_of: :faq
  has_many :users, through: :favorites, source: :user

  enum visibility: Settings.faq.visibility.to_hash

  store_accessor :metadata, :created_by, :updated_by, :approved_by

  scope :actived, -> { where(active: true) }
  scope :unactived, -> { where(active: false) }
  scope :approved, -> { where(approve: true) }
  scope :unapproved, -> { where(approve: false) }
  scope :evidenced, -> { where(evidence: true) }
  scope :on_top, ->(top = Settings.faq.top) { actived.approved.where("counter >= ?", 1).order(counter: :desc).limit(top) }
  pg_search_scope :search_by_title,
                    against: :title,
                    ignoring: :accents,
                    using: {
                      tsearch: { prefix: true, normalization: 2, any_word: true },
                      trigram: { threshold: 0.5, word_similarity: true },
                      dmetaphone: {}
                    },
                    order_within_rank: "faqs.counter DESC"

  before_validation :prerequisite
  validates :title, presence: true, uniqueness: true
  # validates :content, presence: true
  validates :structure, presence: true
  validates :visibility, presence: true
  validates_inclusion_of :visibility, in: visibilities.keys,
                                      message: "state must be one of #{visibilities.keys}"
  validate :must_have_valid_categories

  private

  def prerequisite
    self.created_by ||= Settings.system.username if created_by.blank? && new_record?
    self.updated_by ||= Settings.system.username
  end

  def must_have_valid_categories
    errors.add(:category_list, I18n.t('is_required', scope: '', default: "is required!")) if category_list.blank? && !Rails.env.test?
  end

end

#counterInteger

Returns counter number of requests of Faq.

Returns:

  • (Integer)

    counter number of requests of Faq



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'app/models/faq.rb', line 44

class Faq < ApplicationRecord
  include PgSearch::Model
  acts_as_taggable_on :categories
  has_rich_text :content
  has_many_attached :files
  has_many_attached :instructions
  has_many_attached :models
  has_many :favorites, class_name: 'UserFaq', inverse_of: :faq
  has_many :users, through: :favorites, source: :user

  enum visibility: Settings.faq.visibility.to_hash

  store_accessor :metadata, :created_by, :updated_by, :approved_by

  scope :actived, -> { where(active: true) }
  scope :unactived, -> { where(active: false) }
  scope :approved, -> { where(approve: true) }
  scope :unapproved, -> { where(approve: false) }
  scope :evidenced, -> { where(evidence: true) }
  scope :on_top, ->(top = Settings.faq.top) { actived.approved.where("counter >= ?", 1).order(counter: :desc).limit(top) }
  pg_search_scope :search_by_title,
                    against: :title,
                    ignoring: :accents,
                    using: {
                      tsearch: { prefix: true, normalization: 2, any_word: true },
                      trigram: { threshold: 0.5, word_similarity: true },
                      dmetaphone: {}
                    },
                    order_within_rank: "faqs.counter DESC"

  before_validation :prerequisite
  validates :title, presence: true, uniqueness: true
  # validates :content, presence: true
  validates :structure, presence: true
  validates :visibility, presence: true
  validates_inclusion_of :visibility, in: visibilities.keys,
                                      message: "state must be one of #{visibilities.keys}"
  validate :must_have_valid_categories

  private

  def prerequisite
    self.created_by ||= Settings.system.username if created_by.blank? && new_record?
    self.updated_by ||= Settings.system.username
  end

  def must_have_valid_categories
    errors.add(:category_list, I18n.t('is_required', scope: '', default: "is required!")) if category_list.blank? && !Rails.env.test?
  end

end

#created_atDateTime

Returns date when Faq was created.

Returns:

  • (DateTime)

    date when Faq was created



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'app/models/faq.rb', line 44

class Faq < ApplicationRecord
  include PgSearch::Model
  acts_as_taggable_on :categories
  has_rich_text :content
  has_many_attached :files
  has_many_attached :instructions
  has_many_attached :models
  has_many :favorites, class_name: 'UserFaq', inverse_of: :faq
  has_many :users, through: :favorites, source: :user

  enum visibility: Settings.faq.visibility.to_hash

  store_accessor :metadata, :created_by, :updated_by, :approved_by

  scope :actived, -> { where(active: true) }
  scope :unactived, -> { where(active: false) }
  scope :approved, -> { where(approve: true) }
  scope :unapproved, -> { where(approve: false) }
  scope :evidenced, -> { where(evidence: true) }
  scope :on_top, ->(top = Settings.faq.top) { actived.approved.where("counter >= ?", 1).order(counter: :desc).limit(top) }
  pg_search_scope :search_by_title,
                    against: :title,
                    ignoring: :accents,
                    using: {
                      tsearch: { prefix: true, normalization: 2, any_word: true },
                      trigram: { threshold: 0.5, word_similarity: true },
                      dmetaphone: {}
                    },
                    order_within_rank: "faqs.counter DESC"

  before_validation :prerequisite
  validates :title, presence: true, uniqueness: true
  # validates :content, presence: true
  validates :structure, presence: true
  validates :visibility, presence: true
  validates_inclusion_of :visibility, in: visibilities.keys,
                                      message: "state must be one of #{visibilities.keys}"
  validate :must_have_valid_categories

  private

  def prerequisite
    self.created_by ||= Settings.system.username if created_by.blank? && new_record?
    self.updated_by ||= Settings.system.username
  end

  def must_have_valid_categories
    errors.add(:category_list, I18n.t('is_required', scope: '', default: "is required!")) if category_list.blank? && !Rails.env.test?
  end

end

#evidenceBoolean

Returns if Faq is in evidence.

Returns:

  • (Boolean)

    if Faq is in evidence



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'app/models/faq.rb', line 44

class Faq < ApplicationRecord
  include PgSearch::Model
  acts_as_taggable_on :categories
  has_rich_text :content
  has_many_attached :files
  has_many_attached :instructions
  has_many_attached :models
  has_many :favorites, class_name: 'UserFaq', inverse_of: :faq
  has_many :users, through: :favorites, source: :user

  enum visibility: Settings.faq.visibility.to_hash

  store_accessor :metadata, :created_by, :updated_by, :approved_by

  scope :actived, -> { where(active: true) }
  scope :unactived, -> { where(active: false) }
  scope :approved, -> { where(approve: true) }
  scope :unapproved, -> { where(approve: false) }
  scope :evidenced, -> { where(evidence: true) }
  scope :on_top, ->(top = Settings.faq.top) { actived.approved.where("counter >= ?", 1).order(counter: :desc).limit(top) }
  pg_search_scope :search_by_title,
                    against: :title,
                    ignoring: :accents,
                    using: {
                      tsearch: { prefix: true, normalization: 2, any_word: true },
                      trigram: { threshold: 0.5, word_similarity: true },
                      dmetaphone: {}
                    },
                    order_within_rank: "faqs.counter DESC"

  before_validation :prerequisite
  validates :title, presence: true, uniqueness: true
  # validates :content, presence: true
  validates :structure, presence: true
  validates :visibility, presence: true
  validates_inclusion_of :visibility, in: visibilities.keys,
                                      message: "state must be one of #{visibilities.keys}"
  validate :must_have_valid_categories

  private

  def prerequisite
    self.created_by ||= Settings.system.username if created_by.blank? && new_record?
    self.updated_by ||= Settings.system.username
  end

  def must_have_valid_categories
    errors.add(:category_list, I18n.t('is_required', scope: '', default: "is required!")) if category_list.blank? && !Rails.env.test?
  end

end

#metadataJSONB

Returns content of Faq.

Returns:

  • (JSONB)

    content of Faq



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'app/models/faq.rb', line 44

class Faq < ApplicationRecord
  include PgSearch::Model
  acts_as_taggable_on :categories
  has_rich_text :content
  has_many_attached :files
  has_many_attached :instructions
  has_many_attached :models
  has_many :favorites, class_name: 'UserFaq', inverse_of: :faq
  has_many :users, through: :favorites, source: :user

  enum visibility: Settings.faq.visibility.to_hash

  store_accessor :metadata, :created_by, :updated_by, :approved_by

  scope :actived, -> { where(active: true) }
  scope :unactived, -> { where(active: false) }
  scope :approved, -> { where(approve: true) }
  scope :unapproved, -> { where(approve: false) }
  scope :evidenced, -> { where(evidence: true) }
  scope :on_top, ->(top = Settings.faq.top) { actived.approved.where("counter >= ?", 1).order(counter: :desc).limit(top) }
  pg_search_scope :search_by_title,
                    against: :title,
                    ignoring: :accents,
                    using: {
                      tsearch: { prefix: true, normalization: 2, any_word: true },
                      trigram: { threshold: 0.5, word_similarity: true },
                      dmetaphone: {}
                    },
                    order_within_rank: "faqs.counter DESC"

  before_validation :prerequisite
  validates :title, presence: true, uniqueness: true
  # validates :content, presence: true
  validates :structure, presence: true
  validates :visibility, presence: true
  validates_inclusion_of :visibility, in: visibilities.keys,
                                      message: "state must be one of #{visibilities.keys}"
  validate :must_have_valid_categories

  private

  def prerequisite
    self.created_by ||= Settings.system.username if created_by.blank? && new_record?
    self.updated_by ||= Settings.system.username
  end

  def must_have_valid_categories
    errors.add(:category_list, I18n.t('is_required', scope: '', default: "is required!")) if category_list.blank? && !Rails.env.test?
  end

end

#structureCiText

Returns structure of Faq.

Returns:

  • (CiText)

    structure of Faq



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'app/models/faq.rb', line 44

class Faq < ApplicationRecord
  include PgSearch::Model
  acts_as_taggable_on :categories
  has_rich_text :content
  has_many_attached :files
  has_many_attached :instructions
  has_many_attached :models
  has_many :favorites, class_name: 'UserFaq', inverse_of: :faq
  has_many :users, through: :favorites, source: :user

  enum visibility: Settings.faq.visibility.to_hash

  store_accessor :metadata, :created_by, :updated_by, :approved_by

  scope :actived, -> { where(active: true) }
  scope :unactived, -> { where(active: false) }
  scope :approved, -> { where(approve: true) }
  scope :unapproved, -> { where(approve: false) }
  scope :evidenced, -> { where(evidence: true) }
  scope :on_top, ->(top = Settings.faq.top) { actived.approved.where("counter >= ?", 1).order(counter: :desc).limit(top) }
  pg_search_scope :search_by_title,
                    against: :title,
                    ignoring: :accents,
                    using: {
                      tsearch: { prefix: true, normalization: 2, any_word: true },
                      trigram: { threshold: 0.5, word_similarity: true },
                      dmetaphone: {}
                    },
                    order_within_rank: "faqs.counter DESC"

  before_validation :prerequisite
  validates :title, presence: true, uniqueness: true
  # validates :content, presence: true
  validates :structure, presence: true
  validates :visibility, presence: true
  validates_inclusion_of :visibility, in: visibilities.keys,
                                      message: "state must be one of #{visibilities.keys}"
  validate :must_have_valid_categories

  private

  def prerequisite
    self.created_by ||= Settings.system.username if created_by.blank? && new_record?
    self.updated_by ||= Settings.system.username
  end

  def must_have_valid_categories
    errors.add(:category_list, I18n.t('is_required', scope: '', default: "is required!")) if category_list.blank? && !Rails.env.test?
  end

end

#titleString

Returns Title of Faq.

Returns:

  • (String)

    Title of Faq



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'app/models/faq.rb', line 44

class Faq < ApplicationRecord
  include PgSearch::Model
  acts_as_taggable_on :categories
  has_rich_text :content
  has_many_attached :files
  has_many_attached :instructions
  has_many_attached :models
  has_many :favorites, class_name: 'UserFaq', inverse_of: :faq
  has_many :users, through: :favorites, source: :user

  enum visibility: Settings.faq.visibility.to_hash

  store_accessor :metadata, :created_by, :updated_by, :approved_by

  scope :actived, -> { where(active: true) }
  scope :unactived, -> { where(active: false) }
  scope :approved, -> { where(approve: true) }
  scope :unapproved, -> { where(approve: false) }
  scope :evidenced, -> { where(evidence: true) }
  scope :on_top, ->(top = Settings.faq.top) { actived.approved.where("counter >= ?", 1).order(counter: :desc).limit(top) }
  pg_search_scope :search_by_title,
                    against: :title,
                    ignoring: :accents,
                    using: {
                      tsearch: { prefix: true, normalization: 2, any_word: true },
                      trigram: { threshold: 0.5, word_similarity: true },
                      dmetaphone: {}
                    },
                    order_within_rank: "faqs.counter DESC"

  before_validation :prerequisite
  validates :title, presence: true, uniqueness: true
  # validates :content, presence: true
  validates :structure, presence: true
  validates :visibility, presence: true
  validates_inclusion_of :visibility, in: visibilities.keys,
                                      message: "state must be one of #{visibilities.keys}"
  validate :must_have_valid_categories

  private

  def prerequisite
    self.created_by ||= Settings.system.username if created_by.blank? && new_record?
    self.updated_by ||= Settings.system.username
  end

  def must_have_valid_categories
    errors.add(:category_list, I18n.t('is_required', scope: '', default: "is required!")) if category_list.blank? && !Rails.env.test?
  end

end

#updated_atDateTime

Returns date when Faq was updated.

Returns:

  • (DateTime)

    date when Faq was updated



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'app/models/faq.rb', line 44

class Faq < ApplicationRecord
  include PgSearch::Model
  acts_as_taggable_on :categories
  has_rich_text :content
  has_many_attached :files
  has_many_attached :instructions
  has_many_attached :models
  has_many :favorites, class_name: 'UserFaq', inverse_of: :faq
  has_many :users, through: :favorites, source: :user

  enum visibility: Settings.faq.visibility.to_hash

  store_accessor :metadata, :created_by, :updated_by, :approved_by

  scope :actived, -> { where(active: true) }
  scope :unactived, -> { where(active: false) }
  scope :approved, -> { where(approve: true) }
  scope :unapproved, -> { where(approve: false) }
  scope :evidenced, -> { where(evidence: true) }
  scope :on_top, ->(top = Settings.faq.top) { actived.approved.where("counter >= ?", 1).order(counter: :desc).limit(top) }
  pg_search_scope :search_by_title,
                    against: :title,
                    ignoring: :accents,
                    using: {
                      tsearch: { prefix: true, normalization: 2, any_word: true },
                      trigram: { threshold: 0.5, word_similarity: true },
                      dmetaphone: {}
                    },
                    order_within_rank: "faqs.counter DESC"

  before_validation :prerequisite
  validates :title, presence: true, uniqueness: true
  # validates :content, presence: true
  validates :structure, presence: true
  validates :visibility, presence: true
  validates_inclusion_of :visibility, in: visibilities.keys,
                                      message: "state must be one of #{visibilities.keys}"
  validate :must_have_valid_categories

  private

  def prerequisite
    self.created_by ||= Settings.system.username if created_by.blank? && new_record?
    self.updated_by ||= Settings.system.username
  end

  def must_have_valid_categories
    errors.add(:category_list, I18n.t('is_required', scope: '', default: "is required!")) if category_list.blank? && !Rails.env.test?
  end

end

#visibilityInteger

Returns visibility enum with security visibility of Faq.

Returns:

  • (Integer)

    visibility enum with security visibility of Faq



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'app/models/faq.rb', line 44

class Faq < ApplicationRecord
  include PgSearch::Model
  acts_as_taggable_on :categories
  has_rich_text :content
  has_many_attached :files
  has_many_attached :instructions
  has_many_attached :models
  has_many :favorites, class_name: 'UserFaq', inverse_of: :faq
  has_many :users, through: :favorites, source: :user

  enum visibility: Settings.faq.visibility.to_hash

  store_accessor :metadata, :created_by, :updated_by, :approved_by

  scope :actived, -> { where(active: true) }
  scope :unactived, -> { where(active: false) }
  scope :approved, -> { where(approve: true) }
  scope :unapproved, -> { where(approve: false) }
  scope :evidenced, -> { where(evidence: true) }
  scope :on_top, ->(top = Settings.faq.top) { actived.approved.where("counter >= ?", 1).order(counter: :desc).limit(top) }
  pg_search_scope :search_by_title,
                    against: :title,
                    ignoring: :accents,
                    using: {
                      tsearch: { prefix: true, normalization: 2, any_word: true },
                      trigram: { threshold: 0.5, word_similarity: true },
                      dmetaphone: {}
                    },
                    order_within_rank: "faqs.counter DESC"

  before_validation :prerequisite
  validates :title, presence: true, uniqueness: true
  # validates :content, presence: true
  validates :structure, presence: true
  validates :visibility, presence: true
  validates_inclusion_of :visibility, in: visibilities.keys,
                                      message: "state must be one of #{visibilities.keys}"
  validate :must_have_valid_categories

  private

  def prerequisite
    self.created_by ||= Settings.system.username if created_by.blank? && new_record?
    self.updated_by ||= Settings.system.username
  end

  def must_have_valid_categories
    errors.add(:category_list, I18n.t('is_required', scope: '', default: "is required!")) if category_list.blank? && !Rails.env.test?
  end

end