From b7c5853de5f0f04625eab6389cba9de8b02e48fb Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Mon, 12 May 2025 14:53:31 -0400 Subject: Added streams index --- app/models/stream.rb | 11 +++++++++++ app/models/update.rb | 8 ++++++++ 2 files changed, 19 insertions(+) (limited to 'app/models') diff --git a/app/models/stream.rb b/app/models/stream.rb index 0773143..6a738e2 100644 --- a/app/models/stream.rb +++ b/app/models/stream.rb @@ -8,11 +8,22 @@ class Stream < ApplicationRecord validates :title, presence: true validates :slug, presence: true, format: /\A[-a-z0-9]+\z/ + before_create :set_post_timestamp + def path "/thinks/#{slug}" end + def to_param + slug + end + def taggable self end + + private + def set_post_timestamp + self.latest_post_at = self.created_at + end end diff --git a/app/models/update.rb b/app/models/update.rb index 01907d8..a98a5d4 100644 --- a/app/models/update.rb +++ b/app/models/update.rb @@ -5,6 +5,8 @@ class Update < ApplicationRecord validates :stream, :body, presence: true + after_create :set_latest_timestamp + def path "/thinks/#{stream.slug}\#update-#{id}" end @@ -12,4 +14,10 @@ class Update < ApplicationRecord def taggable stream end + + private + def set_latest_timestamp + self.stream.latest_post_at = self.created_at + self.stream.save! + end end -- cgit 1.4.1