Class: Post

Inherits:
ApplicationRecord
  • Object
show all
Defined in:
app/models/post.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.find_by_slug!(slug) ⇒ Object



20
21
22
# File 'app/models/post.rb', line 20

def self.find_by_slug!(slug)
  Post.find_by(slug: slug) || Post.find_by(id: slug) || raise(ActiveRecord::RecordNotFound.new(slug: slug))
end

Instance Method Details

#published!Object



28
29
30
31
32
33
34
35
36
# File 'app/models/post.rb', line 28

def published!
  self.update(published_at: Time.now)
  super
  if self.user_id
    Notification.create(notify_type: 'press_published',
                        user_id: self.user_id,
                        target: self)
  end
end

#published_atObject



24
25
26
# File 'app/models/post.rb', line 24

def published_at
  super || self.updated_at
end

#to_paramObject



16
17
18
# File 'app/models/post.rb', line 16

def to_param
  self.slug.blank? ? self.id : self.slug
end