37 lines
731 B
Ruby
37 lines
731 B
Ruby
class AllPage < ApplicationRecord
|
|
extend FriendlyId
|
|
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? || title_changed?
|
|
end
|
|
|
|
PAGE_TYPES = {
|
|
1 => 'Strona zwykła',
|
|
2 => 'Strona z listą wpisów',
|
|
3 => 'Artykuł'
|
|
}
|
|
FORM_PAGE_TYPES = [
|
|
['Strona zwykła', '1'],
|
|
['Strona z listą wpisów', '2']
|
|
]
|
|
|
|
def b_destroy
|
|
if self.published_page
|
|
self.published_page.destroy
|
|
end
|
|
end
|
|
def created_name
|
|
Admin.find(self.updated_by).description
|
|
end
|
|
|
|
def created_date
|
|
self.updated_at.to_date
|
|
end
|
|
|
|
end
|