Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix rails 6 save loop callback stack too deep on File upload in admin #892

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion app/models/comfy/cms/file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,12 @@ class Comfy::Cms::File < ActiveRecord::Base
# -- Callbacks ---------------------------------------------------------------
before_validation :assign_label, on: :create
before_create :assign_position
after_save :process_attachment
# active_storage attachment behavior changed in rails 6 - see PR#892 for details
if Rails::VERSION::MAJOR >= 6
before_save :process_attachment
else
after_save :process_attachment
end

# -- Validations -------------------------------------------------------------
validates :label, presence: true
Expand Down
8 changes: 6 additions & 2 deletions app/models/comfy/cms/fragment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,12 @@ class Comfy::Cms::Fragment < ActiveRecord::Base
attr_reader :files

# -- Callbacks ---------------------------------------------------------------
after_save :remove_attachments,
:add_attachments
# active_storage attachment behavior changed in rails 6 - see PR#892 for details
if Rails::VERSION::MAJOR >= 6
before_save :remove_attachments, :add_attachments
else
after_save :remove_attachments, :add_attachments
end

# -- Relationships -----------------------------------------------------------
belongs_to :record, polymorphic: true, touch: true
Expand Down