Я бы предложил создать папку в app/models/callbacks/
и структурировать ваши файлы следующим образом:
- app
- models
- callbacks
user.rb
user.rb
А затем:
class User < ApplicationRecord
after_create ::Callbacks::User
after_destroy ::Callbacks::User
# we have to prepend :: here because it would try to refer to the namespace
# ActiveModel::Validations::Callbacks otherwise
end
&
module Callbacks
module User
# Warning: If you want to refer to the User model in there, you will have to
# prepend it with `::` so it looks up from the root because this module has
# the same name as the User model
# ex:
# ::User::SOME_CONSTANT
# and not
# User::SOME_CONSTANT
def self.after_create(user)
::Services::Emails::Welcome.enqueue!(user_id: user.id)
end
def self.after_destroy(user)
::Services::Emails::Goodbye.enqueue!(user_id: user.id)
end
# ...
end
end
Это простая структура, использующая также Сервисные объекты.