如何从app/lib文件夹中包含模块



我在试图从app/lib文件夹中存在的模块加载类时出现错误。

我已经根据它做了修改

控制器

class SchemasController < ApplicationController
# include Schemas
# require './app/lib/api'
include Operator
end

类下的模块,我必须包括:

# frozen_string_literal: true
module A
module B
class C
@url = "https://something.com"
def self.where(params = {})
response = A::Connection.connect(@url).get('headers', params)
response.body
end
end
end
end

application.rb:

require_relative "boot"

# Pick the frameworks you want:
require 'action_controller/railtie'
require 'active_job/railtie'
require 'action_cable/engine'
require 'action_mailer/railtie'

# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(*Rails.groups)
module AnalyticsQueryBuilder
class Application < Rails::Application
# Initialize configuration defaults for originally generated Rails version.
config.load_defaults 7.0
config.autoload_paths += %W(#{config.root}/lib)
# config.autoload_paths += %W(#{config.root}/lib)
config.autoload_paths += Dir["#{config.root}/lib/**/"]
config.before_configuration do
env_file = File.join(Rails.root, 'config', 'local_env.yml')
if File.exist?(env_file)
YAML.safe_load(File.open(env_file)).each do |key, value|
ENV[key.to_s] = value
end
end
end
Rails.logger = Logger.new($stdout)
config.exceptions_app = routes

end
end

如何在控制器

中包含它

你试过做类似include Api::AnalyticsQueryBuilderMetadataService::Operator的事情吗?

相关内容