Skip to content
This repository was archived by the owner on Jul 25, 2025. It is now read-only.

Commit afa8e16

Browse files
Shpigfordclaude
andcommitted
Fix: Article author update in Avo admin
- Add custom update_model_record method to handle author changes - Properly manage polymorphic authorship association - Destroy existing authorship before creating new one - Handle removal of author (blank selection) This ensures author changes are properly saved when editing articles in Avo. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 4204905 commit afa8e16

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

app/avo/resources/article.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,23 @@ def fields
2323
end
2424
end
2525
end
26+
27+
def update_model_record(model, params, **args)
28+
author_id = params.delete(:author_id)
29+
30+
super(model, params, **args)
31+
32+
if author_id.present?
33+
# Remove existing authorship if present
34+
model.authorship&.destroy
35+
36+
# Create new authorship with the selected author
37+
model.create_authorship(author_id: author_id, role: "primary")
38+
elsif author_id == ""
39+
# If author_id is blank, remove the authorship
40+
model.authorship&.destroy
41+
end
42+
43+
model
44+
end
2645
end

0 commit comments

Comments
 (0)