Instead of trying to suppress from the wrong layer of the stick, just don't touch until published?

This commit is contained in:
David Heinemeier Hansson
2025-11-18 15:35:38 +01:00
parent cec94ff570
commit c606de7b41
2 changed files with 5 additions and 14 deletions
+1 -12
View File
@@ -21,10 +21,7 @@ class CardsController < ApplicationController
end
def update
suppressing_broadcasts_unless_published(@card) do
@card.update! card_params
end
@card.update! card_params
redirect_to @card
end
@@ -46,14 +43,6 @@ class CardsController < ApplicationController
head :forbidden unless Current.user.can_administer_card?(@card)
end
def suppressing_broadcasts_unless_published(card, &block)
if card.published?
yield
else
Board.suppressing_turbo_broadcasts(&block)
end
end
def card_params
params.expect(card: [ :status, :title, :description, :image, tag_ids: [] ])
end
+4 -2
View File
@@ -4,7 +4,7 @@ class Card < ApplicationRecord
Readable, Searchable, Stallable, Statuses, Taggable, Triageable, Watchable
belongs_to :account, default: -> { board.account }
belongs_to :board, touch: true
belongs_to :board
belongs_to :creator, class_name: "User", default: -> { Current.user }
has_many :comments, dependent: :destroy
@@ -13,9 +13,11 @@ class Card < ApplicationRecord
has_rich_text :description
before_save :set_default_title, if: :published?
after_update :handle_board_change, if: :saved_change_to_board_id?
before_create :assign_number
after_save -> { board.touch }, if: :published?
after_update :handle_board_change, if: :saved_change_to_board_id?
scope :reverse_chronologically, -> { order created_at: :desc, id: :desc }
scope :chronologically, -> { order created_at: :asc, id: :asc }
scope :latest, -> { order last_active_at: :desc, id: :desc }