0

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/)
  • 2
    Spilt your module declaration to two lines module Api module V1, instead of a single line. – dbugger Aug 02 '23 at 14:21
  • that did not work unfortunately. I still get the same error – AntonioKaram Aug 08 '23 at 15:52
  • 1
    Do you have any inflections configured? Also note you don't want to add anything to the autoload paths -- your models will be loaded. Could be causing issues. Finally try adding `require_relative '../models/api/v1/log'` to the top of the initializer – dbugger Aug 08 '23 at 16:01
  • Now, running rails s gives me this error: ``` `Exiting` `/usr/share/rvm/gems/ruby-3.2.2/gems/activesupport-7.0.4.3/lib/active_support/core_ext/module/attribute_accessors.rb:54:in mattr_reader: module attributes should be defined directly on class, not singleton (TypeError)`
    `raise TypeError, "module attributes should be defined directly on class, not singleton" if singleton_class?` ```
    – AntonioKaram Aug 08 '23 at 17:43
  • Please update your question with the latest version of the code and include the new error. – dbugger Aug 08 '23 at 18:46

0 Answers0