LoginSignup
0
1

More than 3 years have passed since last update.

Rails APIキーやDBのパスワードをcredential.ymlに記述する

Last updated at Posted at 2020-08-13

※自分用メモです。

1.credentials.yml.encに隠したい情報を記述する

まずcredentials.yml.encを編集します。

コマンド
docker-compose run -e EDITOR=vim web rails credentials:edit

Dockerを使用している場合
vimをインストールしていないとエラーが出るのでインストールしておきましょう。

Dockerfile
RUN apt-get install -y vim
credentials.yml.enc
db:
  password: XXXXXXX

api_key:
  google: XXXXXX

2.呼び出し方法

database.yml

database.yml
  password: <%= Rails.application.credentials.db[:password]%>

~.erb

~~html.erb
<script src="https://maps.googleapis.com/maps/api/js?key=<%= Rails.application.credentials.api_key[:google]%&callback=initMap" async defer></script>

補足

.gitignoreでmaster.keyが記述されているか確認しておきましょう。

gitignoreにはgithubにpushしないファイルを設定するファイルになります。

master.keyはデフォルトで.gitignoreに記述されていますが、念のため確認します。

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1