Class: Faq
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Faq
- 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
Instance Attribute Summary collapse
-
#active ⇒ Boolean
If Faq is active.
-
#approve ⇒ Boolean
If Faq is approved.
-
#content ⇒ Rich Text
Content of Faq.
-
#counter ⇒ Integer
Counter number of requests of Faq.
-
#created_at ⇒ DateTime
Date when Faq was created.
-
#evidence ⇒ Boolean
If Faq is in evidence.
-
#metadata ⇒ JSONB
Content of Faq.
-
#structure ⇒ CiText
Structure of Faq.
-
#title ⇒ String
Title of Faq.
-
#updated_at ⇒ DateTime
Date when Faq was updated.
-
#visibility ⇒ Integer
Visibility enum with security visibility of Faq.
Instance Attribute Details
#active ⇒ Boolean
Returns 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 |
#approve ⇒ Boolean
Returns 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 |
#content ⇒ Rich Text
Returns 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 |
#counter ⇒ Integer
Returns 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_at ⇒ DateTime
Returns 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 |
#evidence ⇒ Boolean
Returns 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 |
#metadata ⇒ JSONB
Returns 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 |
#structure ⇒ CiText
Returns 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 |
#title ⇒ String
Returns 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_at ⇒ DateTime
Returns 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 |
#visibility ⇒ Integer
Returns 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 |