Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Overriding model in gem, adding callback and methods

I've installed the ActiveRecord Reputation System on my app. How would I go about overriding or adding a callback/method to Evaluation model?

In general how do you add to any model for a gem you installed?

like image 286
Katie H Avatar asked Sep 07 '13 01:09

Katie H


1 Answers

Simply reopen 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 the later must be loaded into your code.

like image 53
fotanus Avatar answered Sep 24 '22 19:09

fotanus