If Rails before_filter or after_filter doesn't enough, try before_renders. Tested in Rails 5.1.4
In your Gemfile:
gem 'before_renders'
or system wide:
$ gem install before_renders
Now you can execute methods before your rails application start to render anything. Example in application controller like below :
class ApplicationController < ActionController::Base
before_render :set_layout
def set_layout
# ...
end
end
You can also use in concerns like so:
module PrintableController
extend ActiveSupport::Concern
included do
before_render :update_gst_sum, only: [:new, :show, :print_rf]
end
end