Upgrading Rails Application from 5.0 to 7.0.4.3, NameError uninitialized constant

110 views Asked by At

I recently upgraded my rails application from ruby 2.6.6 to ruby 3.2.2 and rails 5 to rails 7.0.4.3 After upgrading gems that were failing, I am now able to run rails s, but I get this error whenever I do:

=> Booting Puma
=> Rails 7.0.4.3 application starting in development
=> Run `bin/rails server --help` for more startup options
Exiting
/mnt/c/Users/akaram/Desktop/Ruby/hire-right-integration/config/initializers/api_v1_log.rb:2:in `<top (required)>': uninitialized constant Api (NameError)

  Api::V1::Log.logger = Logger.new(Api::V1::Log::LogFile)
         ^^^^^

This is my config/initializers/api_v1_log.rb file:

unless ENV['ASSET_PRECOMPILE'].present?
  Api::V1::Log.logger = Logger.new(Api::V1::Log::LogFile)
  Api::V1::Log.logger.level = 'info'
end

This is my app/models/api/v1/log.rb file:

module Api::V1
  class Log
    LogFile = Rails.root.join("log", "api_v1_#{Rails.env}.log")
    class << self
      cattr_accessor :logger
      delegate :debug, :info, :warn, :error, :fatal, :to => :logger
    end
  end
end

I also added these lines to my config/application.rb file:

    config.eager_load = true 
    config.autoload_paths << Rails.root.join('app')
    config.autoload_paths += %W(#{config.root}/app/models/api/v1/)
0

There are 0 answers