如何包含App/Lib文件夹中的模块
尝试从App/Lib文件夹中存在的模块加载类时,我会遇到错误。
类进行更改
我根据模块下的IT控制器
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
如何将其包括
I am getting an error while trying to load a class from module which is present in app/lib folder.
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:
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否尝试过
之类的操作,包括API :: AnalyticsQueryBuilderMetadataTaService ::操作员
?Have you tried doing something like
include Api::AnalyticsQueryBuilderMetadataService::Operator
?