diff options
Diffstat (limited to 'app/models/update.rb')
| -rw-r--r-- | app/models/update.rb | 15 |
1 files changed, 13 insertions, 2 deletions
| diff --git a/app/models/update.rb b/app/models/update.rb index 41cc453..a98a5d4 100644 --- a/app/models/update.rb +++ b/app/models/update.rb | |||
| @@ -1,12 +1,23 @@ | |||
| 1 | class Update < ApplicationRecord | 1 | class Update < ApplicationRecord |
| 2 | has_many :records, as: :recordable, inverse_of: :recordable | 2 | include Recordable |
| 3 | |||
| 3 | belongs_to :stream | 4 | belongs_to :stream |
| 4 | 5 | ||
| 5 | validates :stream, :body, presence: true | 6 | validates :stream, :body, presence: true |
| 6 | 7 | ||
| 7 | accepts_nested_attributes_for :records, allow_destroy: true | 8 | after_create :set_latest_timestamp |
| 8 | 9 | ||
| 9 | def path | 10 | def path |
| 10 | "/thinks/#{stream.slug}\#update-#{id}" | 11 | "/thinks/#{stream.slug}\#update-#{id}" |
| 11 | end | 12 | end |
| 13 | |||
| 14 | def taggable | ||
| 15 | stream | ||
| 16 | end | ||
| 17 | |||
| 18 | private | ||
| 19 | def set_latest_timestamp | ||
| 20 | self.stream.latest_post_at = self.created_at | ||
| 21 | self.stream.save! | ||
| 22 | end | ||
| 12 | end | 23 | end |
