Module: SeamlessDatabasePool::ControllerFilter
- Defined in:
- lib/seamless_database_pool/controller_filter.rb
Overview
This module provides a simple method of declaring which read pool connection type should be used for various ActionController actions. To use it, you must first mix it into you controller and then call use_database_pool to configure the connection types. Generally you should just do this in ApplicationController and call use_database_pool in your controllers when you need different connection types.
Example:
ApplicationController < ActionController::Base
include SeamlessDatabasePool::ControllerFilter
use_database_pool :all => :persistent, [:save, :delete] => :master
...
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
- #seamless_database_pool_options ⇒ Object
-
#use_master_db_connection_on_next_request ⇒ Object
Force the master connection to be used on the next request.
Class Method Details
.included(base) ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'lib/seamless_database_pool/controller_filter.rb', line 15 def self.included(base) unless base.respond_to?(:use_database_pool) base.extend(ClassMethods) base.class_eval do send(:prepend, ControllerFilterHooks) end end end |
Instance Method Details
#seamless_database_pool_options ⇒ Object
65 66 67 |
# File 'lib/seamless_database_pool/controller_filter.rb', line 65 def self.class. end |
#use_master_db_connection_on_next_request ⇒ Object
Force the master connection to be used on the next request. This is very useful for the Post-Redirect pattern where you post a request to your save action and then redirect the user back to the edit action. By calling this method, you won’t have to worry if the replication engine is slower than the redirect. Normally you won’t need to call this method yourself as it is automatically called when you perform a redirect from within a master connection block. It is made available just in case you have special needs that don’t quite fit into this module’s default logic.
61 62 63 |
# File 'lib/seamless_database_pool/controller_filter.rb', line 61 def use_master_db_connection_on_next_request session[:next_request_db_connection] = :master if session end |