对于 Sinatra 应用程序,config.ru 在以下类中调用“运行”:
class My_init < Sinatra::Base
# Define all environments available in our app
# Set the applications root directory
# Define Root Path
# Require all files in the App directory
# Load database configuration
require './config/database'
ActiveRecord::Base.establish_connection(
:adapter => "mysql2",
:host => settings.db_host,
:database => settings.db_name,
:username => settings.db_username,
:password => settings.db_password
)
end
出于某种原因,无法从此范围访问从 ./config/database 加载的设置。如果我从配置文件本身打印设置,如“p settings.db_host”,一切正常,但是,在这个类中,settings.db_host 是未知的。
有人知道发生了什么吗?
谢谢。