uploadcare / uploadcare-rails

Rails API client that handles uploads and further operations with files by wrapping Uploadcare Upload and REST APIs.
https://uploadcare.com
MIT License
58 stars 70 forks source link

key not found: "UPLOADCARE_SECRET_KEY" (KeyError) #105

Closed GuillaumeOcculy closed 2 years ago

GuillaumeOcculy commented 2 years ago

I have this error when I try to run rails server

$ rails server
/Users/guillaume/.rbenv/versions/3.0.3/lib/ruby/gems/3.0.0/gems/uploadcare-ruby-3.3.1/lib/uploadcare.rb:36:in `fetch': key not found: "UPLOADCARE_SECRET_KEY" (KeyError)
Did you mean?  "UPLOADCARE_PUBLIC_KEY"

This is not a ENV problem because I wrote my credentials directly on config/initializers/uploadcare.rb and still have the same issue

Uploadcare::Rails.configure do |config|
  # Sets your Uploadcare public key.
  config.public_key = 'mypublickey' # ENV.fetch("UPLOADCARE_PUBLIC_KEY", "mypublickey")
  config.secret_key = 'mysecretkey' # ENV.fetch("UPLOADCARE_SECRET_KEY", "mysecretkey") 
...
# .env
UPLOADCARE_PUBLIC_KEY=mypublickey
UPLOADCARE_SECRET_KEY=mysecretkey

The only way to fix it right now is to run export UPLOADCARE_PUBLIC_KEY=demopublickey but it is not the solution

Environment

GuillaumeOcculy commented 2 years ago

I figured it out. If we use dotenv-rails gem, Gemfile should be like this

...
gem "dotenv-rails", require: "dotenv/rails-now", groups: [:development, :test]
gem "uploadcare-rails"

I created a PR https://github.com/uploadcare/uploadcare-rails/pull/106