Redefining the model in gems, adding callbacks and methods

I installed the ActiveRecord reputation system in my application. How do I go override or add a callback / method to the Evaluation model?

In general, how do you add to any model for your gem?

+6
source share
1 answer

Just open the class:

 module ReputationSystem class Evaluation < ActiveRecord::Base def my_method_here puts "Yey!" end end end 

You can put this file in config/initializers/my_monkey_patch.rb or in lib/my_monkey_patch.rb , but later you need to load it into your code.

+8
source

Source: https://habr.com/ru/post/953367/


All Articles