doer123456789
doer123456789

Reputation: 493

Rails On Create - all models/controllers - Do Something

Is there a method to do something in the Application Controller when any new record is created in all models/controllers of the application?

Upvotes: 0

Views: 88

Answers (1)

Emilien Baudet
Emilien Baudet

Reputation: 458

You can do something like this if you want a method before all controllers :

# app/controllers/application_controller.rb

class ApplicationController < ActionController::Base
  before_action :my_method

  protected

  def my_method
    # do stuff
  end
end

Note that you have all these available : https://api.rubyonrails.org/classes/AbstractController/Callbacks/ClassMethods.html

Upvotes: 2

Related Questions