Search code examples
ruby-on-railsahoy

How to make Ahoy gem tracking visits for users with uuid?


I have a User model with uuid for id column.

Ahoy gem creates visits as expected but the user_id is wrong.

Any ideas?


Solution

  • ok. Got that. Ahoy gem doesn't work with user_id as UUID. It takes the first digits from uuid and stores that in user_id for Ahoy::Visit which could look like random value. The solution is to change the user_id type to uuid.

    This migration would do the trick:

    class ChangeAhoyVisits < ActiveRecord::Migration[5.2]
      def change
        Ahoy::Visit.destroy_all
    
        remove_column :ahoy_visits, :user_id, :bigint
        add_column :ahoy_visits, :user_id, :uuid, foreign_key: true, null: true
        add_index :ahoy_visits, :user_id
      end
    end