Overriding model in gem, adding callback and metho

2019-02-13 14:55发布

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?

1条回答
相关推荐>>
2楼-- · 2019-02-13 15:38

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.

查看更多
登录 后发表回答