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<
Your issue might be due to the fact that you are monkey patching the class. When rails tries to reload the constants it is not considering your file.
Try to use module technique as given below.
Add a file called lib/vote_fu_extension.rb
module VoteFuExtension
def self.included(base)
base.has_one :activity_stream_event
base.after_create :create_activity_stream_event
end
def create_activity_stream_event
# something..
end
end
Vote.send(:include, VoteFuExtension)
Add an initializer called config/initializers/vote_fu.rb
require "vote_fu_extension"
Note
If you want to add class methods to the Vote
model refer to this answer.
Shameless plug: My fork of the vote_fu
gem has some new features and enhancements.