Hello :wave: It's not really an issue directly wit...
# support
s
Hello 👋 It's not really an issue directly with Solidus, I added to my solidus project the gem ahoy (https://github.com/ankane/ahoy) for server-side Analytics but I get an error when I try to login in with an User
Copy code
NameError in Spree::UserSessionsController#create

Rails couldn't find a valid model for User association. Please provide the :class_name option on the association declaration. If :class_name is already provided, make sure it's an ActiveRecord::Base subclass.


Extracted source (around line #19):
    authenticate_spree_user!

    if spree_user_signed_in?
      respond_to do |format|
        format.html do
          flash[:success] = I18n.t('spree.logged_in_succesfully')


app/controllers/spree/user_sessions_controller.rb:19:in `create' 
Exception Causes

NameError: uninitialized constant Ahoy::Visit::User raise NameError.new("uninitialized constant #{candidates.first}", candidates.first) ^^^^^
There is not
Ahoy::Visit::User
I guess the controller is looking for
Spree::User
? The issue : https://github.com/ankane/ahoy/issues/513
e
Did you already configure the
current_user
method to match the one used by solidus?
Ahoy.user_method = :spree_current_user
s
I added
Ahoy.user_method = :spree_current_user
into
initializers/ahoy.rb
but still the same error
Copy code
class Ahoy::Store < Ahoy::DatabaseStore
end

# set to true for JavaScript tracking
Ahoy.api = false

# set to true for geocoding (and add the geocoder gem to your Gemfile)
# we recommend configuring local geocoding as well
# see <https://github.com/ankane/ahoy#geocoding>
Ahoy.geocode = false


Ahoy.user_method = :spree_current_user
e
peeking through Ahoy’s code it seems like the generator will setup an active record Ahoy::Visit model for you, if you open app/models/ahoy/visit.rb you should see something like:
Copy code
class Ahoy::Visit < ApplicationRecord
  self.table_name = "ahoy_visits"

  has_many :events, class_name: "Ahoy::Event"
  belongs_to :user, optional: true
end
If that’s the case you should adjust the
belongs_to
association to point toward
Spree::User
instead of a generic
User
, adding
class_name: 'Spree::User'
should be enough
s
Ok ! It's working Thank you @elia :)
👍 1