2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

rubyファイルで環境変数を読み込む【超初心者】

Posted at

数年ぶりにrubyを触ろうと思い、GoogleのSpeechToTextというAPIを使ってみた。
その過程で.envファイルに記載した環境変数を.rbファイルで読み込むやり方を忘れてしまい苦労したので、まとめておく。

#まずは.envファイルを作成
.rbファイルと同じディレクトリ に.envファイルを設置する

#Dotenvインストール
dotenvというgemを使って環境変数を読み込む
どういうgemなのかはdotenvって何?を参照してほしい。

コマンドラインで以下を実行

$ gem install dotenv

そして

bundle install

#.rbファイルに環境変数読み込みメソッドを書く

sample.rb
require 'dotenv'
Dotenv.load

以上

2
0
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
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?