[英]how to Include a module from app/lib folder
I am getting an error while trying to load a class from module which is present in app/lib folder.尝试从 app/lib 文件夹中存在的模块加载类时出现错误。
I had made changes according to it我已经根据它进行了更改
Controller控制器
class SchemasController < ApplicationController
# include Schemas
# require './app/lib/api'
include Operator
end
class under module which I have to include:我必须包括的模块下的类:
# 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:应用程序.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
How to include it in Controller如何将其包含在控制器中
您是否尝试过类似include Api::AnalyticsQueryBuilderMetadataService::Operator
?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.