@@ -19,26 +19,33 @@ module Middleware
19
19
# that informs the application when to read from a primary or read from a
20
20
# replica.
21
21
#
22
- # To use the DatabaseSelector in your application with default settings add
23
- # the following options to your environment config:
22
+ # To use the DatabaseSelector in your application with default settings,
23
+ # run the provided generator.
24
24
#
25
- # # This require is only necessary when using `rails new app --minimal`
26
- # require "active_support/core_ext/integer/time"
25
+ # bin/rails g active_record:multi_db
27
26
#
28
- # class Application < Rails::Application
27
+ # This will create a file named +config/initializers/multi_db.rb+ with the
28
+ # following contents:
29
+ #
30
+ # Rails.application.configure do
29
31
# config.active_record.database_selector = { delay: 2.seconds }
30
32
# config.active_record.database_resolver = ActiveRecord::Middleware::DatabaseSelector::Resolver
31
33
# config.active_record.database_resolver_context = ActiveRecord::Middleware::DatabaseSelector::Resolver::Session
32
34
# end
33
35
#
34
- # New applications will include these lines commented out in the production.rb.
36
+ # Alternatively you can set the options in your environment config or
37
+ # any other config file loaded on boot.
35
38
#
36
39
# The default behavior can be changed by setting the config options to a
37
40
# custom class:
38
41
#
39
42
# config.active_record.database_selector = { delay: 2.seconds }
40
43
# config.active_record.database_resolver = MyResolver
41
44
# config.active_record.database_resolver_context = MyResolver::MySession
45
+ #
46
+ # Note: If you are using `rails new my_app --minimal` you will need to call
47
+ # `require "active_support/core_ext/integer/time"` to load the libaries
48
+ # for +Time+.
42
49
class DatabaseSelector
43
50
def initialize ( app , resolver_klass = nil , context_klass = nil , options = { } )
44
51
@app = app
0 commit comments