0
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 1 year has passed since last update.

Rubyで設定ファイル読み込み

Posted at

はじめに

Rubyで設定ファイルの読み込み方法を調べたので、そのメモ書きになります。
Docker上でのRailsサーバーを使用しています。

設定ファイル用意

今回はtest.confファイルを以下内容で用意します。

[api]
key = ABC

Gemfile

Gemfileに以下を追加します。

group :development do
  gem 'inifile' ★追加

イメージの再構築

docker-compose build --no-cache

ソース

require "inifile" ★追記

class Search < ApplicationRecord
  def self.searchApi()
    ini = IniFile.load("setting.conf") ★追記
    searcher.key = ini["api"]["key"] ★追記

起動

docker-compose up -d

以上で、設定ファイルが読み込めるようになりました。

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