pdfshop/app/models/all_page.rb

56 lines
1.4 KiB
Ruby

# == Schema Information
#
# Table name: all_pages
#
# id :integer not null, primary key
# name :string(40) not null
# title :string(255) not null
# slug :string(255) not null
# meta_description :string(255)
# nofollow :boolean default(FALSE)
# type_of :integer not null
# article_id :integer
# small_text :text(65535)
# full_text :text(16777215)
# updated_at :datetime
# updated_by :bigint(8)
# published :boolean default(FALSE), not null
#
# Model for allpages that are not published
class AllPage < ApplicationRecord
extend FriendlyId
include FriendlyFinder
friendly_id :title, use: :slugged
validates :name, presence: true, uniqueness: true
belongs_to :article, optional: true
has_one :published_page
before_destroy :b_destroy
def should_generate_new_friendly_id?
slug.blank? || will_save_change_to_attribute?(:title)
end
PAGE_TYPES = {
1 => 'Strona zwykła',
2 => 'Strona z listą wpisów',
3 => 'Artykuł'
}.freeze
FORM_PAGE_TYPES = [
['Strona zwykła', '1'],
['Strona z listą wpisów', '2']
].freeze
def b_destroy
published_page && published_page.destroy
end
def created_name
Admin.find(updated_by).description
end
def created_date
updated_at.to_date
end
end