Class: Integral::Post
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Integral::Post
- Extended by:
- FriendlyId
- Includes:
- ActionView::Helpers::DateHelper, LazyContentable, Webhook::Observable
- Defined in:
- app/models/integral/post.rb
Overview
Represents a user post
Class Method Summary collapse
- .integral_icon ⇒ Object
-
.listable_options ⇒ Hash
Listable options to be used within a RecordSelector widget.
Instance Method Summary collapse
-
#increment_count!(ip_address) ⇒ Object
Increments the view count of the post if a PostViewing is successfully added.
-
#tag_context ⇒ String
Current tag context.
-
#tags ⇒ Array
ActsAsTaggableOn::Tag tags associated with this post.
-
#to_card ⇒ Hash
The instance as a card.
-
#to_list_item ⇒ Hash
The instance as a list item.
-
#url ⇒ String
URL to frontend route.
Methods included from Webhook::Delivery
#deliver_webhook, #deliver_webhook_event
Methods included from LazyContentable
Methods inherited from ApplicationRecord
Class Method Details
.integral_icon ⇒ Object
103 104 105 |
# File 'app/models/integral/post.rb', line 103 def self.integral_icon 'rss' end |
.listable_options ⇒ Hash
Returns listable options to be used within a RecordSelector widget.
94 95 96 97 98 99 100 101 |
# File 'app/models/integral/post.rb', line 94 def self. { icon: 'rss', record_title: I18n.t('integral.backend.record_selector.posts.record'), selector_path: Engine.routes.url_helpers.list_backend_posts_path, selector_title: I18n.t('integral.backend.record_selector.posts.title') } end |
Instance Method Details
#increment_count!(ip_address) ⇒ Object
Increments the view count of the post if a PostViewing is successfully added
55 56 57 |
# File 'app/models/integral/post.rb', line 55 def increment_count!(ip_address) increment!(:view_count) if PostViewing.add(self, ip_address) end |
#tag_context ⇒ String
Returns Current tag context.
108 109 110 |
# File 'app/models/integral/post.rb', line 108 def tag_context status end |
#tags ⇒ Array
Returns ActsAsTaggableOn::Tag tags associated with this post.
113 114 115 |
# File 'app/models/integral/post.rb', line 113 def (tag_context) end |
#to_card ⇒ Hash
Returns the instance as a card.
73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'app/models/integral/post.rb', line 73 def to_card image_url = featured_image.file.url if featured_image { image: image_url, description: title, url: url, attributes: [ { key: I18n.t('integral.records.attributes.author'), value: .name }, { key: I18n.t('integral.records.attributes.views'), value: view_count }, { key: I18n.t('integral.records.attributes.status'), value: I18n.t("integral.records.status.#{status}") }, { key: I18n.t('integral.records.attributes.updated_at'), value: I18n.l(updated_at) } ] } end |
#to_list_item ⇒ Hash
Returns the instance as a list item.
60 61 62 63 64 65 66 67 68 69 70 |
# File 'app/models/integral/post.rb', line 60 def to_list_item subtitle = published_at.present? ? I18n.t('integral.blog.posted_ago', time: time_ago_in_words(published_at)) : I18n.t('integral.users.status.draft') { id: id, title: title, subtitle: subtitle, description: description, image: featured_image, url: Integral::Engine.routes.url_helpers.post_url(self) } end |