Rails API, Cloudinary: неинициализированная константа CLOUDINARY_CLOUD_NAME (NameError) - PullRequest
0 голосов
/ 21 мая 2018

Я загружал и удалял изображения на Cloudinary в моем Rails API, пока я не начал получать сообщение об ошибке.Я не могу запустить и запустить сервер.

Любые идеи, что является причиной этого?

Я установил облачный гем и мои конфигурации в config / initializer / cloudinary.rb примерно так, с моимучетные данные в application.yml:

Cloudinary.config do |config|
  config.cloud_name = ENV[CLOUDINARY_CLOUD_NAME]
  config.api_key = ENV[CLOUDINARY_API_KEY]
  config.api_secret =  ENV[CLOUDINARY_API_SECRET]
  config.secure = true
  config.cdn_subdomain = true
end

Я делаю ссылки на Cloudinary в моем контроллере изображений примерно так:

result = Cloudinary::Uploader.upload(image, options = {})

Вот полная ошибка:

*** В качестве обновления я поместил облачный URL в мой application.yml и закомментировал cloudinary.rb, и теперь он работает, но если кто-нибудь сможет пролить свет на причину возникновения неинициализированной постоянной ошибки, я был бы признателен.****

    /Users/ok/live-projects/a-pj-api/config/initializers/cloudinary.rb:2:in `block in <top (required)>': uninitialized constant CLOUDINARY_CLOUD_NAME (NameError)
    from /usr/local/opt/rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/cloudinary-1.9.1/lib/cloudinary.rb:82:in `config'
    from /Users/ok/live-projects/a-pj-api/config/initializers/cloudinary.rb:1:in `<top (required)>'
    from /usr/local/opt/rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/railties-5.1.5/lib/rails/engine.rb:655:in `block in load_config_initializer'
    from /usr/local/opt/rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/activesupport-5.1.5/lib/active_support/notifications.rb:168:in `instrument'
    from /usr/local/opt/rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/railties-5.1.5/lib/rails/engine.rb:654:in `load_config_initializer'
    from /usr/local/opt/rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/railties-5.1.5/lib/rails/engine.rb:612:in `block (2 levels) in <class:Engine>'
    from /usr/local/opt/rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/railties-5.1.5/lib/rails/engine.rb:611:in `each'
    from /usr/local/opt/rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/railties-5.1.5/lib/rails/engine.rb:611:in `block in <class:Engine>'
    from /usr/local/opt/rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/railties-5.1.5/lib/rails/initializable.rb:30:in `instance_exec'
    from /usr/local/opt/rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/railties-5.1.5/lib/rails/initializable.rb:30:in `run'
    from /usr/local/opt/rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/railties-5.1.5/lib/rails/initializable.rb:59:in `block in run_initializers'
    from /usr/local/opt/rbenv/versions/2.4.2/lib/ruby/2.4.0/tsort.rb:228:in `block in tsort_each'
    from /usr/local/opt/rbenv/versions/2.4.2/lib/ruby/2.4.0/tsort.rb:350:in `block (2 levels) in each_strongly_connected_component'
    from /usr/local/opt/rbenv/versions/2.4.2/lib/ruby/2.4.0/tsort.rb:422:in `block (2 levels) in each_strongly_connected_component_from'
    from /usr/local/opt/rbenv/versions/2.4.2/lib/ruby/2.4.0/tsort.rb:431:in `each_strongly_connected_component_from'
    from /usr/local/opt/rbenv/versions/2.4.2/lib/ruby/2.4.0/tsort.rb:421:in `block in each_strongly_connected_component_from'
    from /usr/local/opt/rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/railties-5.1.5/lib/rails/initializable.rb:48:in `each'
    from /usr/local/opt/rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/railties-5.1.5/lib/rails/initializable.rb:48:in `tsort_each_child'
    from /usr/local/opt/rbenv/versions/2.4.2/lib/ruby/2.4.0/tsort.rb:415:in `call'
    from /usr/local/opt/rbenv/versions/2.4.2/lib/ruby/2.4.0/tsort.rb:415:in `each_strongly_connected_component_from'
    from /usr/local/opt/rbenv/versions/2.4.2/lib/ruby/2.4.0/tsort.rb:349:in `block in each_strongly_connected_component'
    from /usr/local/opt/rbenv/versions/2.4.2/lib/ruby/2.4.0/tsort.rb:347:in `each'
    from /usr/local/opt/rbenv/versions/2.4.2/lib/ruby/2.4.0/tsort.rb:347:in `call'
    from /usr/local/opt/rbenv/versions/2.4.2/lib/ruby/2.4.0/tsort.rb:347:in `each_strongly_connected_component'
    from /usr/local/opt/rbenv/versions/2.4.2/lib/ruby/2.4.0/tsort.rb:226:in `tsort_each'
    from /usr/local/opt/rbenv/versions/2.4.2/lib/ruby/2.4.0/tsort.rb:205:in `tsort_each'
    from /usr/local/opt/rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/railties-5.1.5/lib/rails/initializable.rb:58:in `run_initializers'
    from /usr/local/opt/rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/railties-5.1.5/lib/rails/application.rb:353:in `initialize!'
    from /Users/okadachikara/live-projects/apartment-pj-api/config/environment.rb:5:in `<top (required)>'
    from config.ru:3:in `require_relative'
    from config.ru:3:in `block in <main>'
    from /usr/local/opt/rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/rack-2.0.4/lib/rack/builder.rb:55:in `instance_eval'
    from /usr/local/opt/rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/rack-2.0.4/lib/rack/builder.rb:55:in `initialize'
    from config.ru:in `new'
    from config.ru:in `<main>'
    from /usr/local/opt/rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/rack-2.0.4/lib/rack/builder.rb:49:in `eval'
    from /usr/local/opt/rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/rack-2.0.4/lib/rack/builder.rb:49:in `new_from_string'
    from /usr/local/opt/rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/rack-2.0.4/lib/rack/builder.rb:40:in `parse_file'
    from /usr/local/opt/rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/rack-2.0.4/lib/rack/server.rb:319:in `build_app_and_options_from_config'
    from /usr/local/opt/rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/rack-2.0.4/lib/rack/server.rb:219:in `app'
    from /usr/local/opt/rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/railties-5.1.5/lib/rails/commands/server/server_command.rb:24:in `app'
    from /usr/local/opt/rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/rack-2.0.4/lib/rack/server.rb:354:in `wrapped_app'
    from /usr/local/opt/rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/railties-5.1.5/lib/rails/commands/server/server_command.rb:80:in `log_to_stdout'
    from /usr/local/opt/rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/railties-5.1.5/lib/rails/commands/server/server_command.rb:42:in `start'
    from /usr/local/opt/rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/railties-5.1.5/lib/rails/commands/server/server_command.rb:135:in `block in perform'
    from /usr/local/opt/rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/railties-5.1.5/lib/rails/commands/server/server_command.rb:130:in `tap'
    from /usr/local/opt/rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/railties-5.1.5/lib/rails/commands/server/server_command.rb:130:in `perform'
    from /usr/local/opt/rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/thor-0.20.0/lib/thor/command.rb:27:in `run'
    from /usr/local/opt/rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/thor-0.20.0/lib/thor/invocation.rb:126:in `invoke_command'
    from /usr/local/opt/rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/thor-0.20.0/lib/thor.rb:387:in `dispatch'
    from /usr/local/opt/rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/railties-5.1.5/lib/rails/command/base.rb:63:in `perform'
    from /usr/local/opt/rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/railties-5.1.5/lib/rails/command.rb:44:in `invoke'
    from /usr/local/opt/rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/railties-5.1.5/lib/rails/commands.rb:16:in `<top (required)>'
    from /Users/ok/live-projects/a-pj-api/bin/rails:9:in `require'
    from /Users/ok/live-projects/ap-pj-api/bin/rails:9:in `<top (required)>'
    from /usr/local/opt/rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/spring-2.0.2/lib/spring/client/rails.rb:28:in `load'
    from /usr/local/opt/rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/spring-2.0.2/lib/spring/client/rails.rb:28:in `call'
    from /usr/local/opt/rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/spring-2.0.2/lib/spring/client/command.rb:7:in `call'
    from /usr/local/opt/rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/spring-2.0.2/lib/spring/client.rb:30:in `run'
    from /usr/local/opt/rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/spring-2.0.2/bin/spring:49:in `<top (required)>'
    from /usr/local/opt/rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/spring-2.0.2/lib/spring/binstub.rb:31:in `load'
    from /usr/local/opt/rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/spring-2.0.2/lib/spring/binstub.rb:31:in `<top (required)>'
    from /usr/local/opt/rbenv/versions/2.4.2/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:68:in `require'
    from /usr/local/opt/rbenv/versions/2.4.2/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:68:in `require'
    from /Users/ok/live-projects/ap-pj-api/bin/spring:15:in `<top (required)>'
    from ./bin/rails:3:in `load'
    from ./bin/rails:3:in `<main>'

1 Ответ

0 голосов
/ 21 мая 2018

Из общих спецификаций кажется, что вместо указания переменной среды вы упомянули переменную как константу.

Измените код на приведенный ниже:

Cloudinary.config do |config|
  config.cloud_name = ENV["CLOUDINARY_CLOUD_NAME"]
  config.api_key = ENV["CLOUDINARY_API_KEY"]
  config.api_secret =  ENV["CLOUDINARY_API_SECRET"]
  config.secure = true
  config.cdn_subdomain = true
end
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...