首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

在Sinatra中灵便地配置Environments

2013-01-05 
在Sinatra中灵活地配置Environmentsconfigure :development doDataMapper.setup(:default, postgres://lo

在Sinatra中灵活地配置Environments

configure :development do DataMapper.setup(:default, "postgres://localhost/test") DataMapper.finalize.auto_upgrade! end configure :test do DataMapper.setup(:default, "sqlite::memory:") end configure :production do load_postgres_on_cloudfoundry DataMapper.finalize.auto_upgrade! end?greeting: Welcome to my file configurable application

require "sinatra"require "sinatra/config_file"config_file 'path/to/config.yml'get '/' do @greeting = settings.greeting haml :indexend# The rest of your classic application code goes here...

require "sinatra/base"require "sinatra/config_file"class MyApp < Sinatra::Base register Sinatra::ConfigFile config_file 'path/to/config.yml' get '/' do @greeting = settings.greeting haml :index end # The rest of your modular application code goes here...end?上面的例子是最简单的用法,下面再说明一下如何针对不同的环境分别进行配置:

development: foo: development bar: bartest: foo: test bar: barproduction: foo: production bar: bar

foo: development: development test: test production: productionbar: bar

set :environments, %w{development test production staging}

参考文档:

? ? 1.http://www.sinatrarb.com/contrib/config_file.html???

热点排行