0

I'm using Ahoy with Mongoid store. Any advice is much appreciated!

My issue is that, for efficiency's sake, every time a new ahoy event is created, I want to update that elements count so I can do stuff like sorting by pageviews. My plan was to use a mongoid callback like after_create to update a counter everytime an event is generated. something like:

class Ahoy::Event

  after_create :update_pageviews

  def update_pageviews
    case self.name
    when 'Viewed post'
      p = Monologue::Post.find(properties[:post])
      p.pageviews = p.pageviews + 1
      p.save
    end
  end

however, the callback never seems to even get fired.

  1. Is there a better way to handle this? Pulling the counts live is too slow for me, so I need to store it somewhere.
  2. Why isn't the callback firing?

1 Answers1

0

Update for anyone else who runs into this. The issue had to do with Ahoy's use of an a BSON::Binary type instead of (what Mongoid currently uses) BSON::ObjectId. Had to convert my IDs for mongodb to behave happily.