gpt4 book ai didi

ruby-on-rails - 存储在 lib (heroku) 中的生产未初始化常量自定义类

转载 作者:行者123 更新时间:2023-12-04 16:40:02 25 4
gpt4 key购买 nike

我有一个存储在/lib (/lib/buffer_app.rb) 中的自定义类:

require 'HTTParty'

class BufferApp
include HTTParty
base_uri 'https://api.bufferapp.com/1'

def initialize(token, id)
@token = token
@id = id
end

def create(text)
message_hash = {"text" => text, "profile_ids[]" => @id, "access_token" => @token}

response = BufferApp.post('/updates/create.json', :body => {"text" => text, "profile_ids[]" => @id, "access_token" => @token})
end
end

我正在尝试在 Active Admin 资源中使用此类,并在生产(Heroku)时收到以下错误:
NameError (uninitialized constant Admin::EventsController::BufferApp):

值得注意的是,我的 application.rb 中有这一行,并且此功能在本地开发中有效:
config.autoload_paths += %W(#{Rails.root}/lib)

如果我尝试 include BufferApprequire 'BufferApp'该行本身会导致错误。我有命名空间问题吗?这需要是一个模块吗?还是简单的配置疏忽?

最佳答案

改变这个

config.autoload_paths += %W(#{Rails.root}/lib)

对此
config.eager_load_paths += %W(#{Rails.root}/lib)
eager_load_paths将在生产和开发中按需加载。这样做,您不需要明确要求每个文件。

查看更多信息 this answer .

关于ruby-on-rails - 存储在 lib (heroku) 中的生产未初始化常量自定义类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17215184/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com