Class: Post

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

Direct Known Subclasses

Blog, Code, Image, Link, Quote, Video

Constant Summary collapse

@@per_page =
5

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details



27
28
29
# File 'app/models/post.rb', line 27

def self.find_by_permalink_or_id(param)
  Post.find_by_permalink(param) || Post.find(param)
end

.typesObject



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

def self.types
  Dir[File.expand_path('../posts',__FILE__)+'/*.rb'].each { |f| require_dependency f }
  self.subclasses.collect(&:to_s).sort
end

Instance Method Details

#assetObject



14
15
16
# File 'app/models/post.rb', line 14

def asset
  assets.first
end

#format_published_atObject



54
55
56
# File 'app/models/post.rb', line 54

def format_published_at
  self.published_at = Time.now if self.published_at.nil?
end

#titleObject



38
39
40
# File 'app/models/post.rb', line 38

def title
  read_attribute(:title).blank? ? "Post #{id}" : read_attribute(:title)
end

#to_paramObject



18
19
20
# File 'app/models/post.rb', line 18

def to_param
  permalink.blank? ? id.to_s : permalink
end