Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def today

def display_banner
# Cache banners to avoid repeated queries during page render
@banners ||= Banner.published.select("id, content").to_a
@banners ||= Banner.active.select("id, content").to_a
return if @banners.empty?

safe_content_array = @banners.map { |banner|
Expand Down
6 changes: 6 additions & 0 deletions app/models/banner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,10 @@ class Banner < ApplicationRecord
def name
content.truncate(50)
end

scope :active, -> {
where(show: true)
.where("started_at IS NULL OR started_at <= ?", Time.current)
.where("ended_at IS NULL OR ended_at >= ?", Time.current)
}
end
6 changes: 6 additions & 0 deletions db/migrate/20260305105227_add_timeto_banner.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class AddTimetoBanner < ActiveRecord::Migration[8.1]
def change
add_column :banners, :started_at, :datetime
add_column :banners, :ended_at, :datetime
end
end
Loading
Loading