Skip to content

Commit 37f69a0

Browse files
ashkandblock
authored andcommitted
Add sample for reading env variables in yml
1 parent 8e220b3 commit 37f69a0

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#### 0.10.1 (Next)
44

5+
* [#90](https://github.com/slack-ruby/slack-ruby-bot-server/pull/90): Update ActiveRecord sample app to support ENV variables in `postgresql.yml` - [@ashkan18](https://github.com/ashkan18).
56
* Your contribution here.
67

78
#### 0.10.0 (2019/3/23)

sample_apps/sample_app_activerecord/config.ru

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,15 @@ Bundler.require :default
44

55
require_relative 'commands'
66
require 'yaml'
7+
require 'erb'
78

8-
ActiveRecord::Base.establish_connection(YAML.load_file('config/postgresql.yml')[ENV['RACK_ENV']])
9+
ActiveRecord::Base.establish_connection(
10+
YAML.safe_load(
11+
ERB.new(
12+
File.read('config/postgresql.yml')
13+
).result
14+
)[ENV['RACK_ENV']]
15+
)
916

1017
NewRelic::Agent.manual_start
1118

sample_apps/sample_app_activerecord/config/postgresql.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ test:
1414

1515
production:
1616
<<: *default
17-
database: slack_ruby_bot_server_production
17+
url: <%= ENV["DATABASE_URL"] %>

0 commit comments

Comments
 (0)