Files
fizzy/app/models/card.rb
T
Jorge Manrubia fb83b5e70e Merge branch 'main' into add-card-description
* main:
  Fix trailing empty line
  --skip-server in ci setup
  Enumerate all the options for logging in
  Have an empty first-run tenant too
  Convert to conventional Rails style
  Seed multiple seed accounts with basic DSL
  Stlye
  No need to run Solid Cache in development
  Use morphing to replace the card and exclude turbo frames from being replaced
  Name is already schema and UI required
  Cards have a not-null schema and collections destroy all cards on deletion
  No longer used
  Inline touch check thats only used once

# Conflicts:
#	app/views/cards/_container.html.erb
2025-04-21 16:04:06 +02:00

37 lines
1.0 KiB
Ruby

class Card < ApplicationRecord
include Assignable, Colored, Engageable, Eventable, Golden,
Messages, Notifiable, Pinnable, Closeable, Searchable, Staged,
Statuses, Taggable, Watchable
belongs_to :collection, touch: true
belongs_to :creator, class_name: "User", default: -> { Current.user }
has_many :notifications, dependent: :destroy
has_one_attached :image, dependent: :purge_later
has_markdown :description
scope :reverse_chronologically, -> { order created_at: :desc, id: :desc }
scope :chronologically, -> { order created_at: :asc, id: :asc }
scope :latest, -> { order updated_at: :desc, id: :desc }
scope :indexed_by, ->(index) do
case index
when "newest" then reverse_chronologically
when "oldest" then chronologically
when "latest" then latest
when "stalled" then chronologically
when "closed" then closed
end
end
def title=(new_title)
self[:title] = new_title.presence || "Untitled"
end
def cache_key
[ super, collection.name ].compact.join("/")
end
end