AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • Início
  • system&network
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • Início
  • system&network
    • Recentes
    • Highest score
    • tags
  • Ubuntu
    • Recentes
    • Highest score
    • tags
  • Unix
    • Recentes
    • tags
  • DBA
    • Recentes
    • tags
  • Computer
    • Recentes
    • tags
  • Coding
    • Recentes
    • tags
Início / coding / Perguntas / 79557310
Accepted
tolia k
tolia k
Asked: 2025-04-06 01:28:30 +0800 CST2025-04-06 01:28:30 +0800 CST 2025-04-06 01:28:30 +0800 CST

Erro constante não inicializado do Rails somente em produção

  • 772

Recebo esse erro quando tento iniciar o servidor no modo de produção

=> Booting Puma
=> Rails 8.0.1 application starting in production
=> Run `bin/rails server --help` for more startup options
[dotenv] Loaded .env
Exiting
C:/Users/tolia/.local/share/gem/ruby/3.3.0/gems/zeitwerk-2.7.2/lib/zeitwerk/cref.rb:63:in `const_get': uninitialized constant Openai::Openai (NameError)

    @mod.const_get(@cname, false)
        ^^^^^^^^^^
Did you mean?  OpenAI
        from C:/Users/tolia/.local/share/gem/ruby/3.3.0/gems/zeitwerk-2.7.2/lib/zeitwerk/cref.rb:63:in `get'
        from C:/Users/tolia/.local/share/gem/ruby/3.3.0/gems/zeitwerk-2.7.2/lib/zeitwerk/loader/eager_load.rb:173:in `block in actual_eager_load_dir'
        from C:/Users/tolia/.local/share/gem/ruby/3.3.0/gems/zeitwerk-2.7.2/lib/zeitwerk/loader/helpers.rb:47:in `block in ls'
        from C:/Users/tolia/.local/share/gem/ruby/3.3.0/gems/zeitwerk-2.7.2/lib/zeitwerk/loader/helpers.rb:25:in `each'
        from C:/Users/tolia/.local/share/gem/ruby/3.3.0/gems/zeitwerk-2.7.2/lib/zeitwerk/loader/helpers.rb:25:in `ls'
        from C:/Users/tolia/.local/share/gem/ruby/3.3.0/gems/zeitwerk-2.7.2/lib/zeitwerk/loader/eager_load.rb:168:in `actual_eager_load_dir'
        from C:/Users/tolia/.local/share/gem/ruby/3.3.0/gems/zeitwerk-2.7.2/lib/zeitwerk/loader/eager_load.rb:17:in `block (2 levels) in eager_load'
        from C:/Users/tolia/.local/share/gem/ruby/3.3.0/gems/zeitwerk-2.7.2/lib/zeitwerk/loader/eager_load.rb:16:in `each'
        from C:/Users/tolia/.local/share/gem/ruby/3.3.0/gems/zeitwerk-2.7.2/lib/zeitwerk/loader/eager_load.rb:16:in `block in eager_load'
        from C:/Users/tolia/.local/share/gem/ruby/3.3.0/gems/zeitwerk-2.7.2/lib/zeitwerk/loader/eager_load.rb:10:in `synchronize'
        from C:/Users/tolia/.local/share/gem/ruby/3.3.0/gems/zeitwerk-2.7.2/lib/zeitwerk/loader/eager_load.rb:10:in `eager_load'
        from C:/Users/tolia/.local/share/gem/ruby/3.3.0/gems/zeitwerk-2.7.2/lib/zeitwerk/loader.rb:430:in `block in eager_load_all'
        from C:/Users/tolia/.local/share/gem/ruby/3.3.0/gems/zeitwerk-2.7.2/lib/zeitwerk/loader.rb:428:in `each'
        from C:/Users/tolia/.local/share/gem/ruby/3.3.0/gems/zeitwerk-2.7.2/lib/zeitwerk/loader.rb:428:in `eager_load_all'
        from C:/Users/tolia/.local/share/gem/ruby/3.3.0/gems/railties-8.0.1/lib/rails/application/finisher.rb:79:in `block in <module:Finisher>'
        from C:/Users/tolia/.local/share/gem/ruby/3.3.0/gems/railties-8.0.1/lib/rails/initializable.rb:32:in `instance_exec'
        from C:/Users/tolia/.local/share/gem/ruby/3.3.0/gems/railties-8.0.1/lib/rails/initializable.rb:32:in `run'
        from C:/Users/tolia/.local/share/gem/ruby/3.3.0/gems/railties-8.0.1/lib/rails/initializable.rb:61:in `block in run_initializers'
        from D:/APPS/Ruby33-x64/lib/ruby/3.3.0/tsort.rb:231:in `block in tsort_each'
        from D:/APPS/Ruby33-x64/lib/ruby/3.3.0/tsort.rb:353:in `block (2 levels) in each_strongly_connected_component'
        from D:/APPS/Ruby33-x64/lib/ruby/3.3.0/tsort.rb:434:in `each_strongly_connected_component_from'
        from D:/APPS/Ruby33-x64/lib/ruby/3.3.0/tsort.rb:352:in `block in each_strongly_connected_component'
        from D:/APPS/Ruby33-x64/lib/ruby/3.3.0/tsort.rb:350:in `each'
        from D:/APPS/Ruby33-x64/lib/ruby/3.3.0/tsort.rb:350:in `call'
        from D:/APPS/Ruby33-x64/lib/ruby/3.3.0/tsort.rb:350:in `each_strongly_connected_component'
        from D:/APPS/Ruby33-x64/lib/ruby/3.3.0/tsort.rb:229:in `tsort_each'
        from D:/APPS/Ruby33-x64/lib/ruby/3.3.0/tsort.rb:208:in `tsort_each'
        from C:/Users/tolia/.local/share/gem/ruby/3.3.0/gems/railties-8.0.1/lib/rails/initializable.rb:60:in `run_initializers'
        from C:/Users/tolia/.local/share/gem/ruby/3.3.0/gems/railties-8.0.1/lib/rails/application.rb:440:in `initialize!'
        from D:/PROGRAMMING/RUBY/addmemore_backend/config/environment.rb:5:in `<main>'
        from config.ru:3:in `require_relative'
        from config.ru:3:in `block (2 levels) in <main>'
        from C:/Users/tolia/.local/share/gem/ruby/3.3.0/gems/rack-3.1.8/lib/rack/builder.rb:108:in `eval'
        from C:/Users/tolia/.local/share/gem/ruby/3.3.0/gems/rack-3.1.8/lib/rack/builder.rb:108:in `new_from_string'
        from C:/Users/tolia/.local/share/gem/ruby/3.3.0/gems/rack-3.1.8/lib/rack/builder.rb:97:in `load_file'
        from C:/Users/tolia/.local/share/gem/ruby/3.3.0/gems/rack-3.1.8/lib/rack/builder.rb:67:in `parse_file'
        from C:/Users/tolia/.local/share/gem/ruby/3.3.0/gems/rackup-2.2.1/lib/rackup/server.rb:354:in `build_app_and_options_from_config'
        from C:/Users/tolia/.local/share/gem/ruby/3.3.0/gems/rackup-2.2.1/lib/rackup/server.rb:263:in `app'
        from C:/Users/tolia/.local/share/gem/ruby/3.3.0/gems/rackup-2.2.1/lib/rackup/server.rb:424:in `wrapped_app'
        from C:/Users/tolia/.local/share/gem/ruby/3.3.0/gems/rackup-2.2.1/lib/rackup/server.rb:326:in `block in start'
        from C:/Users/tolia/.local/share/gem/ruby/3.3.0/gems/rackup-2.2.1/lib/rackup/server.rb:382:in `handle_profiling'
        from C:/Users/tolia/.local/share/gem/ruby/3.3.0/gems/rackup-2.2.1/lib/rackup/server.rb:325:in `start'
        from C:/Users/tolia/.local/share/gem/ruby/3.3.0/gems/railties-8.0.1/lib/rails/commands/server/server_command.rb:38:in `start'
        from C:/Users/tolia/.local/share/gem/ruby/3.3.0/gems/railties-8.0.1/lib/rails/commands/server/server_command.rb:145:in `block in perform'
        from <internal:kernel>:90:in `tap'
        from C:/Users/tolia/.local/share/gem/ruby/3.3.0/gems/railties-8.0.1/lib/rails/commands/server/server_command.rb:136:in `perform'
        from C:/Users/tolia/.local/share/gem/ruby/3.3.0/gems/thor-1.3.2/lib/thor/command.rb:28:in `run'
        from C:/Users/tolia/.local/share/gem/ruby/3.3.0/gems/thor-1.3.2/lib/thor/invocation.rb:127:in `invoke_command'
        from C:/Users/tolia/.local/share/gem/ruby/3.3.0/gems/railties-8.0.1/lib/rails/command/base.rb:178:in `invoke_command'
        from C:/Users/tolia/.local/share/gem/ruby/3.3.0/gems/thor-1.3.2/lib/thor.rb:538:in `dispatch'
        from C:/Users/tolia/.local/share/gem/ruby/3.3.0/gems/railties-8.0.1/lib/rails/command/base.rb:73:in `perform'
        from C:/Users/tolia/.local/share/gem/ruby/3.3.0/gems/railties-8.0.1/lib/rails/command.rb:65:in `block in invoke'
        from C:/Users/tolia/.local/share/gem/ruby/3.3.0/gems/railties-8.0.1/lib/rails/command.rb:143:in `with_argv'
        from C:/Users/tolia/.local/share/gem/ruby/3.3.0/gems/railties-8.0.1/lib/rails/command.rb:63:in `invoke'
        from C:/Users/tolia/.local/share/gem/ruby/3.3.0/gems/railties-8.0.1/lib/rails/commands.rb:18:in `<main>'
        from D:/APPS/Ruby33-x64/lib/ruby/3.3.0/bundled_gems.rb:69:in `require'
        from D:/APPS/Ruby33-x64/lib/ruby/3.3.0/bundled_gems.rb:69:in `block (2 levels) in replace_require'
        from C:/Users/tolia/.local/share/gem/ruby/3.3.0/gems/bootsnap-1.18.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
        from D:/PROGRAMMING/RUBY/addmemore_backend/bin/rails:4:in `<main>'

Tenho openai.rbna app/services/openai/pasta require "net/http" require "uri" require "json"

class OpenAI
  def initialize(api_key)
    @api_key = api_key
  end

  def generate_comments(number_of_comments, post_description, customer_query)
    # some code ...
  end
end

Também incluo em application_controller.rb

require_relative "../services/openai/openai"

Anteriormente, resolvi esses problemas renomeando pastas, módulos e classes, mas agora ficou muito chato, porque a classe é nomeada OpenAI, mas o Rails tenta encontrá-laOpenai

ruby-on-rails
  • 1 1 respostas
  • 36 Views

1 respostas

  • Voted
  1. Best Answer
    mechnicov
    2025-04-06T03:45:58+08:002025-04-06T03:45:58+08:00

    Do guia oficial

    Por padrão, o Rails configura o Zeitwerk para flexionar nomes de arquivo com String#camelize. Por exemplo, ele espera que app/controllers/users_controller.rbdefina a constante UsersControllerporque é isso que "users_controller".camelizeretorna.

    Isso significa que some_entity.rbdeve conter SomeEntityclasse (ou módulo). O mesmo para as pastas, o nome da pasta deve corresponder ao nome do namespace (módulo)

    Eu tenho openai.rbemapp/services/openai/

    Neste caso, o Rails await Openai::Openaiconstant. Se sua constante for OpenAI, você deve mover seu arquivo para app/services/openai.rbe personalizar a inflexão

    # config/initializers/zeitwerk.rb
    loader = Rails.autoloaders.main
    
    loader.inflector.inflect(
      'openai' => 'OpenAI',
    )
    

    ou

    # config/initializers/inflections.rb
    ActiveSupport::Inflector.inflections(:en) do |inflect|
      inflect.acronym 'OpenAI'
    end
    
    • 1

relate perguntas

  • Exibir informações do servidor Rails no Active Admin

  • Grape api (rails) - constante não inicializada Endpoints::TodoAPI (NameError)

  • Qual retorno de chamada devo usar para obter o valor anterior?

  • Rails - Pare de servir qualquer visualização de front-end

  • Obtendo erro de método indefinido em ruby ​​on rails enquanto o método é definido

Sidebar

Stats

  • Perguntas 205573
  • respostas 270741
  • best respostas 135370
  • utilizador 68524
  • Highest score
  • respostas
  • Marko Smith

    Reformatar números, inserindo separadores em posições fixas

    • 6 respostas
  • Marko Smith

    Por que os conceitos do C++20 causam erros de restrição cíclica, enquanto o SFINAE antigo não?

    • 2 respostas
  • Marko Smith

    Problema com extensão desinstalada automaticamente do VScode (tema Material)

    • 2 respostas
  • Marko Smith

    Vue 3: Erro na criação "Identificador esperado, mas encontrado 'import'" [duplicado]

    • 1 respostas
  • Marko Smith

    Qual é o propósito de `enum class` com um tipo subjacente especificado, mas sem enumeradores?

    • 1 respostas
  • Marko Smith

    Como faço para corrigir um erro MODULE_NOT_FOUND para um módulo que não importei manualmente?

    • 6 respostas
  • Marko Smith

    `(expression, lvalue) = rvalue` é uma atribuição válida em C ou C++? Por que alguns compiladores aceitam/rejeitam isso?

    • 3 respostas
  • Marko Smith

    Um programa vazio que não faz nada em C++ precisa de um heap de 204 KB, mas não em C

    • 1 respostas
  • Marko Smith

    PowerBI atualmente quebrado com BigQuery: problema de driver Simba com atualização do Windows

    • 2 respostas
  • Marko Smith

    AdMob: MobileAds.initialize() - "java.lang.Integer não pode ser convertido em java.lang.String" para alguns dispositivos

    • 1 respostas
  • Martin Hope
    Fantastic Mr Fox Somente o tipo copiável não é aceito na implementação std::vector do MSVC 2025-04-23 06:40:49 +0800 CST
  • Martin Hope
    Howard Hinnant Encontre o próximo dia da semana usando o cronógrafo 2025-04-21 08:30:25 +0800 CST
  • Martin Hope
    Fedor O inicializador de membro do construtor pode incluir a inicialização de outro membro? 2025-04-15 01:01:44 +0800 CST
  • Martin Hope
    Petr Filipský Por que os conceitos do C++20 causam erros de restrição cíclica, enquanto o SFINAE antigo não? 2025-03-23 21:39:40 +0800 CST
  • Martin Hope
    Catskul O C++20 mudou para permitir a conversão de `type(&)[N]` de matriz de limites conhecidos para `type(&)[]` de matriz de limites desconhecidos? 2025-03-04 06:57:53 +0800 CST
  • Martin Hope
    Stefan Pochmann Como/por que {2,3,10} e {x,3,10} com x=2 são ordenados de forma diferente? 2025-01-13 23:24:07 +0800 CST
  • Martin Hope
    Chad Feller O ponto e vírgula agora é opcional em condicionais bash com [[ .. ]] na versão 5.2? 2024-10-21 05:50:33 +0800 CST
  • Martin Hope
    Wrench Por que um traço duplo (--) faz com que esta cláusula MariaDB seja avaliada como verdadeira? 2024-05-05 13:37:20 +0800 CST
  • Martin Hope
    Waket Zheng Por que `dict(id=1, **{'id': 2})` às vezes gera `KeyError: 'id'` em vez de um TypeError? 2024-05-04 14:19:19 +0800 CST
  • Martin Hope
    user924 AdMob: MobileAds.initialize() - "java.lang.Integer não pode ser convertido em java.lang.String" para alguns dispositivos 2024-03-20 03:12:31 +0800 CST

Hot tag

python javascript c++ c# java typescript sql reactjs html

Explore

  • Início
  • Perguntas
    • Recentes
    • Highest score
  • tag
  • help

Footer

AskOverflow.Dev

About Us

  • About Us
  • Contact Us

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve