[RUBY] What to do if you can't find your API key after deploying to Rails heroku

Implemented function

Get latitude and longitude from the address entered using gem geocoder. Get the Google API Key and display the map on the app.

Problems that occurred

It worked fine in the development environment, but in the production environment after deployment When I checked the operation, the map was not displayed for the address I entered and nothing was returned.

I guessed

When I checked the console, it said No Apikeys, ʻInvalidkey`, so I guess it was due to the API key.

Since I lacked knowledge of API, is there a problem with the code written in the development environment or a problem with the setting of Google API? I dig deeper thinking that, but I can't find any articles that could be solved.

By the way, I used gem" dotenv-rails " for the API key, put it in the environment variable in .env, and hid it in .gitignore.

If you put in the Google Maps Platform API Checker, which is a Chrome extension, I was able to confirm that the error character and a sentence of the code containing the API key were displayed, but the API key itself was not found.

In other words, the environment variables have not been called.

problem solving

When I googled around here, I could see that I was addicted to the swamp (laughs). I decided to calm down and think about it.

** ... Maybe it's because you're deploying to heroku? ?? ** **

So when I try to google, this is bingo!

** Heroku doesn't deploy files in .gitignore ** You said you need to set environment variables with heroku config: set.

[heroku] Manipulating environment variables

I will refer to this article and set environment variables on heroku.

I was able to solve it safely! !! !!

Recommended Posts

What to do if you can't find your API key after deploying to Rails heroku
What to do if you can't use the rails command
[Rails] What to do if you can't get parameters with form_with
What to do if the Rails server can't start
What to do if rails server can't be stopped
What to do if you can't bundle update and bundle install after installing Ruby 3.0.0 in the Rails tutorial
What to do if the update does not take effect after deploying Rails AWS
# What to do if you accidentally do rails db: migrate: drop
What to do if you can't find the JDK you put in SDKMAN after migrating from bash to zsh on macOS
[Rails] What to do if you accidentally install bundle in the production environment in your local environment
[Rails] What to do if you can't get an error message with the errors method
What to do if you get a "302" error in your controller unit test code in Rails
What to do if you install Ubuntu
What to do if you can't install the plugin from the Eclipse marketplace
What to do if you get an error when you hit Heroku logs
What to do if you push incorrect information
What to do if you can't activate the select box created by bootstrap-select
What to do if you get an error on heroku rake db: migrate
What to do if you accidentally create a model
What to do if you can't get the text of an element in Selenium
What to do if you get the error Couldn't find Item without an ID
What to do if you get an error saying "Could not find a JavaScript runtime." When starting rails server
What to do if you get a java.io.IOException in GlassFish
[Java] [Spring] What to do if you cannot Autowire with Type Mismatch after annotating Spring Security
What to do if you enable UFW on Ubuntu VM on GCP and you can't connect to SSH
What to do if you get an error in Basic authentication during Rails test code
What to do if you get a gcc error in Docker
[Rails] What to do if data is not registered in DB
What to do if you get a "Mysql2 :: Error: Operand should contain 1 column (s)" error in Rails
What to do if the Rails page doesn't appear in Rails tutorial 1.3.2
What to do if Cloud9 is full in the Rails tutorial
What to do if you get a DISPLAY error in gym.render ()
What to do after Vagrant install
What to do if you get angry with OpenSSL with pyenv install
What to do if you get "Changes not staged for commit:" when you git status after git add.
What to do if you forget the root password in CentOS7
What to do if you cannot roll back the migration (UnknownMigrationVersionError)
What to do if you get an error with bundle install by entering gem'bcrypt' in your Gemfile
What to do if you should have installed Rails but an error occurs with rails -v (for beginners)
What to do if the image posted by refile disappears after setting a 404 error page in Rails
[Rails / Docker] What to do if access is denied by the browser (localhost: 3000) after adding a gem
What to do if you get a groovy warning in Thymeleaf Layout
What to do if the background image is not applied after deployment
[Composer] [Laravel] What to do if you cannot install due to insufficient memory
What to do if you get an uninitialized constant Likes Controller error
What to do if deployment fails on Heroku (Ruby app not detected)
What to do if you don't like the code generated by swagger-codegen-cli
[Rails] When deploying Heroku you can't define an already defined column'''Coping method
What to do if you get a MiniMagick vulnerability alert on GitHub
What to do after updating Dockerfile, docker-compose.yml
[Rails] What to do if you get an error saying "Could not find a JavaScript runtime." When executing the rails s command on Catalina
What to do if you get an "A server is already running." Error when you try to start the rails server
What to do if you get Could not save master table to file after importing a project in Eclipse
What to do if you get a SQLite3 :: BusyException: database is locked error
What to do when you think you can't do Groovy-> Java in IntelliJ IDEA CE
What to do if you get the error message unrecognized selector send to instance "***"
What to do if you have installed Java for OS X on macOS
What to do if Docker Desktop fails to launch on your M1 MacBook Pro
What to do if you get angry if you don't have nokogiri while installing wp2txt
What to do if you get To install the missing version, run `gem install bundler: 2.1.4`
What to do if the rails server doesn't run out on AWS cloud9