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<
A word of caution: this is a very old gem (last commit is 3 years old) and by the looks of it won't work with rails 3.x as is. In Rails 3.x engines makes this sort of stuff way easier.
As I understand it the problem in the first case is not that the vote model gets reloaded (it shouldn't) but that the activity_stream_event
model is reloaded. Because the vote model isn't reloaded the association is left hanging onto the version of the activity_stream_event
class from before the reload. Since rails guts out classes before they get reloaded, this causes problems.
With this in mine, try this hack:
#in config/initializers/abstract_vote.rb
AbstractVote = Vote
AbstractVote.abstract_class = true
Object.send :remove_const, :Vote
#in app/models/vote.rb
class Vote < AbstractVote
after_create :create_activity_stream_event
has_one :activity_stream_event
def create_activity_stream_event
end
end
What this does is allow you to have your own Vote class that inherits from the one in the gem.
But again, I urge you to find something more up to date or roll your own (the gem is only ~250 lines of ruby)