Uploaded image for project: 'Mongoid'
  1. Mongoid
  2. MONGOID-4992

Update Persistence Documentation to remove calls to deprecated ActionController methods

    • 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
      

            Assignee:
            oleg.pudeyev@mongodb.com Oleg Pudeyev (Inactive)
            Reporter:
            alex.bevilacqua@mongodb.com Alex Bevilacqua
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: