Reputation: 1351
I have been uploading and deleting images on Cloudinary in my Rails API just fine until I started getting the subject error. I cannot get the server up and running.
Any ideas what is causing this?
I installed the cloudinary gem and have my configurations in config/initializers/cloudinary.rb like so, with my credentials in 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
I'm making references to Cloudinary in my image controller like so:
result = Cloudinary::Uploader.upload(image, options = {})
Here is the full error:
*** As update, I placed the cloudinary url in my application.yml and commented out cloudinary.rb, and it works now, but if anyone can shed light on why the uninitialized constant error came up, I would appreciate it. ****
/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>'
Upvotes: 0
Views: 701
Reputation: 2727
From the specifications shared it seems that rather than specifying environment variable you have mentioned the variable as a constant.
Change the code to the below mentioned:
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
Upvotes: 1