diff options
| author | erdgeist <erdgeist@erdgeist.org> | 2026-07-06 16:59:19 +0200 |
|---|---|---|
| committer | erdgeist <erdgeist@erdgeist.org> | 2026-07-06 16:59:19 +0200 |
| commit | 3dbf522783dfce496884e05559dc962cae4b1e1b (patch) | |
| tree | 9b5c90ee05027dda9eb24b4c1968674a4a1e029f | |
| parent | 1393b3de31d95b1aa5122d6da37bd3259830bdb6 (diff) | |
Apply slug immediately for never-published nodes
staged_slug existed to protect a live public URL from changing until
an editor explicitly publishes - correct once a node has a head, but
nodes_controller#update wrote to it unconditionally, so a brand-new
node being renamed before its first-ever publish showed a stale slug
in previews (e.g. nodes#new's resulting-path preview) that silently
diverged from what would actually go live.
Node#staged_slug= now applies directly to slug when head is blank -
nothing is live yet, so there's nothing to protect. Once head is
present, defers to staged_slug exactly as before. Verified both paths
directly: a never-published node's slug now updates immediately, and
an already-published node's rename still stays deferred until the
next publish, unchanged from existing behavior.
| -rw-r--r-- | app/models/node.rb | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/app/models/node.rb b/app/models/node.rb index ba94e2a..2177f15 100644 --- a/app/models/node.rb +++ b/app/models/node.rb | |||
| @@ -94,6 +94,14 @@ class Node < ApplicationRecord | |||
| 94 | self.draft.reload | 94 | self.draft.reload |
| 95 | end | 95 | end |
| 96 | 96 | ||
| 97 | def staged_slug=(value) | ||
| 98 | if head.blank? | ||
| 99 | self.slug = value | ||
| 100 | else | ||
| 101 | super | ||
| 102 | end | ||
| 103 | end | ||
| 104 | |||
| 97 | def publish_draft! | 105 | def publish_draft! |
| 98 | # Return nil if nothing to publish and no staged changes | 106 | # Return nil if nothing to publish and no staged changes |
| 99 | return nil unless self.draft || staged_slug || staged_parent_id | 107 | return nil unless self.draft || staged_slug || staged_parent_id |
