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

Commit d4dd12c

Browse files
committed
Revert "Fix: Simplify article author management in Avo"
This reverts commit 8f766a5.
1 parent 8f766a5 commit d4dd12c

1 file changed

Lines changed: 25 additions & 8 deletions

File tree

app/avo/resources/article.rb

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,36 @@ class Avo::Resources::Article < Avo::BaseResource
1010

1111
def fields
1212
field :id, as: :id
13+
field :title, as: :text
14+
field :slug, as: :text
15+
field :content, as: :easy_mde
16+
field :publish_at, as: :date_time
1317
field :author_name, as: :text, hide_on: [ :forms ]
18+
field :author, as: :belongs_to, searchable: true, display_with_value: -> { record.name }
1419

1520
tabs do
16-
tab "General" do
17-
field :title, as: :text
18-
field :slug, as: :text
19-
field :content, as: :easy_mde
20-
field :publish_at, as: :date_time
21-
end
22-
23-
tab "Author" do
21+
tab "Author Details" do
2422
field :authorship, as: :has_one
2523
end
2624
end
2725
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
2845
end

0 commit comments

Comments
 (0)