Using variables (database requests) in the config.ru
I'm new to Rack and try to get my head around it running Ruby on Rails 3.0.0.beta4.
I'm starting a Rack app in the config.ru file but would like to use a variable there that is stored in my database. Is it even possible to get a database value back before the application is loaded or am I missing the point completely?
I'm using th开发者_运维问答e Rack Google Analytics gem and would like to get the UA key from the database:
require "rack-google-analytics"
use Rack::GoogleAnalytics, :tracker => "UA-xxxxx-x"
Thanks!
Of course you can do someting like that
require "rack-google-analytics"
require "active_record"
ActiveRecord::Base.establish_connection ...
...
use Rack::GoogleAnalytics, :tracker => "UA-xxxxx-x"
but you should understand than all code over line
use Rack::GoogleAnalytics, :tracker => "UA-xxxxx-x"
will be executed only once, when your web server is starting
精彩评论