-
Type: Improvement
-
Resolution: Fixed
-
Priority: Minor - P4
-
Affects Version/s: None
-
Component/s: Docs
-
Fully Compatible
https://docs.mongodb.com/mongoid/7.1/tutorials/mongoid-persistence/index.html#global-override
Sample code is:
class BandsController < ApplicationController before_filter :switch_database after_filter :reset_database private def switch_database I18n.locale = params[:locale] || I18n.default_locale Mongoid.override_database("my_db_name_#{I18n.locale}") end def reset_database Mongoid.override_database(nil) end end
The *_filter syntax has been deprecated since Rails 5.1 (May 2017). New syntax is *_action (see https://guides.rubyonrails.org/action_controller_overview.html#filters):
class BandsController < ApplicationController before_action :switch_database after_action :reset_database private def switch_database I18n.locale = params[:locale] || I18n.default_locale Mongoid.override_database("my_db_name_#{I18n.locale}") end def reset_database Mongoid.override_database(nil) end end