Class: Blogit::Post
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Blogit::Post
- Defined in:
- app/models/blogit/post.rb
Class Method Summary collapse
-
.active_with_id(id) ⇒ Object
Finds an active post with given id.
-
.for_feed ⇒ Object
The posts to be displayed for RSS and XML feeds/sitemaps.
Instance Method Summary collapse
-
#blogger ⇒ Object
The blogger (User, Admin, etc.) who wrote this Post.
-
#blogger_display_name ⇒ Object
The blogger who wrote this Post’s display name.
-
#blogger_twitter_username ⇒ Object
If there’s a blogger and that blogger responds to :twitter_username, returns that.
-
#comments ⇒ Object
The Comments written on this Post.
- #comments=(value) ⇒ Object
-
#published_at ⇒ Object
TODO: Get published at working properly!.
-
#short_body ⇒ Object
The content of the Post to be shown in the RSS feed.
- #to_param ⇒ Object
Class Method Details
.active_with_id(id) ⇒ Object
Finds an active post with given id
id - The id of the Post to find
Returns a Blogit::Post Raises ActiveRecord::NoMethodError if no Blogit::Post could be found
64 65 66 |
# File 'app/models/blogit/post.rb', line 64 def self.active_with_id(id) active.find(id) end |
.for_feed ⇒ Object
The posts to be displayed for RSS and XML feeds/sitemaps
Returns an ActiveRecord::Relation
54 55 56 |
# File 'app/models/blogit/post.rb', line 54 def self.for_feed active.order('created_at DESC') end |
Instance Method Details
#blogger ⇒ Object
The blogger (User, Admin, etc.) who wrote this Post
Returns a Blogger (polymorphic type)
33 |
# File 'app/models/blogit/post.rb', line 33 belongs_to :blogger, :polymorphic => true |
#blogger_display_name ⇒ Object
109 110 111 112 113 114 115 116 117 |
# File 'app/models/blogit/post.rb', line 109 def blogger_display_name return "" if blogger.blank? if blogger.respond_to?(Blogit.configuration.blogger_display_name_method) blogger.send(Blogit.configuration.blogger_display_name_method) else method_name = Blogit.configuration.blogger_display_name_method raise ConfigurationError, "#{blogger.class}##{method_name} is not defined" end end |
#blogger_twitter_username ⇒ Object
If there’s a blogger and that blogger responds to :twitter_username, returns that. Otherwise, returns nil
121 122 123 124 125 |
# File 'app/models/blogit/post.rb', line 121 def blogger_twitter_username if blogger and blogger.respond_to?(:twitter_username) blogger.twitter_username end end |
#comments ⇒ Object
The Comments written on this Post
Returns an ActiveRecord::Relation instance
39 |
# File 'app/models/blogit/post.rb', line 39 has_many :comments, :class_name => "Blogit::Comment" |
#comments=(value) ⇒ Object
98 99 100 101 |
# File 'app/models/blogit/post.rb', line 98 def comments=(value) check_comments_config super(value) end |
#published_at ⇒ Object
TODO: Get published at working properly!
73 74 75 |
# File 'app/models/blogit/post.rb', line 73 def published_at created_at end |
#short_body ⇒ Object
The content of the Post to be shown in the RSS feed.
Returns description when Blogit.configuration.show_post_description is true Returns body when Blogit.configuration.show_post_description is false
85 86 87 88 89 90 91 |
# File 'app/models/blogit/post.rb', line 85 def short_body if Blogit.configuration.show_post_description description else body end end |
#to_param ⇒ Object
77 78 79 |
# File 'app/models/blogit/post.rb', line 77 def to_param "#{id}-#{title.parameterize}" end |