Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- list do
- scopes [:unscoped]
- end
- class Post < ActiveRecord::Base
- default_scope { archived: false }
- end
- class RailsAdmin::Post < ActiveRecord::Base
- self.table_name = "posts"
- end
- ### Monkey pactch for unscoped records in admin panel
- require 'rails_admin/main_controller'
- module RailsAdmin
- class MainController
- alias_method :old_get_collection, :get_collection
- alias_method :old_get_object, :get_object
- def get_collection(model_config, scope, pagination)
- old_get_collection(model_config, model_config.abstract_model.model.unscoped, pagination)
- end
- def get_object
- raise RailsAdmin::ObjectNotFound unless (object = @abstract_model.model.unscoped.find(params[:id]))
- @object = RailsAdmin::Adapters::ActiveRecord::AbstractObject.new(object)
- end
- end
- end
- #
- # Monkey patch to remove default_scope
- #
- require 'rails_admin/adapters/active_record'
- module RailsAdmin::Adapters::ActiveRecord
- def get(id)
- return unless object = scoped.where(primary_key => id).first
- AbstractObject.new object
- end
- def scoped
- model.unscoped
- end
- end
- module RailsAdminFindUnscopedPatch
- def get(id)
- RailsAdmin::Adapters::Mongoid::AbstractObject.new(model.unscoped.find(id))
- rescue
- super
- end
- end
- RailsAdmin::Adapters::Mongoid.prepend(RailsAdminFindUnscopedPatch)
Add Comment
Please, Sign In to add comment