render メソッドを、run_callbacks で包むだけのモンキーパッチ
# frozen_string_literal: true
module BeforeRender
extend ActiveSupport::Concern
included do
define_callbacks :render
prepend RenderPatch
end
module RenderPatch
def render(*options, &block)
run_callbacks(:render) do
super(*options, &block)
end
end
end
class_methods do
def before_render(*names, &block)
_insert_callbacks(names, block) do |name, options|
set_callback(:render, :before, name, options)
end
end
end
end