Class: PublishedPage
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- PublishedPage
- Defined in:
- app/models/published_page.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.publish!(publisher, topic, slug, options = {}) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'app/models/published_page.rb', line 26 def self.publish!(publisher, topic, slug, = {}) pp = nil results = transaction do pp = find_or_initialize_by(topic: topic) pp.slug = slug.strip pp.public = [:public] || false if pp.save StaffActionLogger.new(publisher).log_published_page(topic.id, slug) [true, pp] end end results || [false, pp] end |
.unpublish!(publisher, topic) ⇒ Object
44 45 46 47 48 49 |
# File 'app/models/published_page.rb', line 44 def self.unpublish!(publisher, topic) if pp = PublishedPage.find_by(topic_id: topic.id) pp.destroy! StaffActionLogger.new(publisher).log_unpublished_page(topic.id, pp.slug) end end |
Instance Method Details
#path ⇒ Object
18 19 20 |
# File 'app/models/published_page.rb', line 18 def path "/pub/#{slug}" end |
#slug_format ⇒ Object
10 11 12 13 14 15 16 |
# File 'app/models/published_page.rb', line 10 def slug_format if slug !~ /\A[a-zA-Z\-\_0-9]+\z/ errors.add(:slug, I18n.t("publish_page.slug_errors.invalid")) elsif %w[check-slug by-topic].include?(slug) errors.add(:slug, I18n.t("publish_page.slug_errors.unavailable")) end end |