我试图设置Sinatra环境变量,以便传递符号,而不仅仅是字符串。现在我收到以下错误消息:DEPRECATION WARNING: Passing a string to ActiveRecord::Base.establish_connection for a configuration lookup is deprecated, please pass a symbol (:development) instead.
我的.env
文件:(使用dotenv gem)
RACK_ENV=development
我的environments.rb
文件(我在app.rb文件中需要这个)
environment = ENV['RACK_ENV']
db_options = YAML.load(File.read('./config/database.yml')[environment])
ActiveRecord::Base.establish_connection(db_options)
我尝试将.env设置为:
RACK_ENV=:development
但是这会引发错误no implicit conversion of nil into String
答案 0 :(得分:0)
由于Sinatra-Active Record默认读取database.yml文件,这意味着我不需要显式读取该文件。相反,我只写了以下内容:
.ENV
RACK_ENV=development
environments.rb
environment = ENV['RACK_ENV'].to_sym
ActiveRecord::Base.establish_connection(environment)