B
B
Bogdan2017-10-10 13:03:41
Ruby on Rails
Bogdan, 2017-10-10 13:03:41

Rails how to work with config file?

Hello. I change have a simple ini file

Color=F0

PgServiceName=postgresql-x64-10
PGDATA=C:\Program Files\PostgreSQL\10\data\
PgBin=C:\Program Files\PostgreSQL\10\bin\
PGUSER=postgres
PGPASSWORD=1

What is the best way to read the value of certain parameters from it without resorting to the use of third-party gems? Thank you.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman Mirilaczvili, 2017-10-10
@2ord

It's simple. Read the file line by line, extracting the key=value on each line:

PATTERN = /(.+)=(.+)/
match_data = line.match(PATTERN)
p match_data[1]
p match_data[2]

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question