Re-open an ActiveRecord model that's provided by a gem

后端 未结 6 1954
旧时难觅i
旧时难觅i 2021-02-10 05:53

I\'m trying to extend an ActiveRecord model (Vote) that a gem (https://github.com/peteonrails/vote_fu) provides to my application. (I.e., there is no vote.rb<

6条回答
  •  渐次进展
    2021-02-10 06:57

    I'd try what agmcleod suggested in the comments but instead of putting it in lib, put it in config/initializers/vote.rb:

     class Vote
       after_create :create_activity_stream_event
       has_one :activity_stream_event
    
       def create_activity_stream_event
       # something..
       end
     end
    

    Of course, you could fork the gem, make your modifications and link to your forked version in your Gemfile (that's my preference).

提交回复
热议问题