simple_crm/app/models/published_page.rb

35 lines
682 B
Ruby

class PublishedPage < ApplicationRecord
extend FriendlyId
friendly_id :title, :use => :slugged
belongs_to :all_page
belongs_to :article, optional: true
def should_generate_new_friendly_id?
slug.blank? || title_changed?
end
def published
true
end
def created_name
admin = Admin.find(self.created_by)
admin.blank? ? 'nieznany' : admin.description
end
def created_date
self.created_at.to_date
end
def article_friendly
ret = ''
if self.type_of == 3 && self.article
pp = self.article.published_pages.where('type_of = 2').first
unless pp.blank?
ret = pp.friendly_id
end
end
return ret
end
end