Guest User

Untitled

a guest
Jan 16th, 2018
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. list do
  2. scopes [:unscoped]
  3. end
  4.  
  5. class Post < ActiveRecord::Base
  6. default_scope { archived: false }
  7. end
  8.  
  9. class RailsAdmin::Post < ActiveRecord::Base
  10. self.table_name = "posts"
  11. end
  12.  
  13. ### Monkey pactch for unscoped records in admin panel
  14. require 'rails_admin/main_controller'
  15. module RailsAdmin
  16. class MainController
  17. alias_method :old_get_collection, :get_collection
  18. alias_method :old_get_object, :get_object
  19.  
  20. def get_collection(model_config, scope, pagination)
  21. old_get_collection(model_config, model_config.abstract_model.model.unscoped, pagination)
  22. end
  23.  
  24. def get_object
  25. raise RailsAdmin::ObjectNotFound unless (object = @abstract_model.model.unscoped.find(params[:id]))
  26. @object = RailsAdmin::Adapters::ActiveRecord::AbstractObject.new(object)
  27. end
  28. end
  29. end
  30.  
  31. #
  32. # Monkey patch to remove default_scope
  33. #
  34. require 'rails_admin/adapters/active_record'
  35. module RailsAdmin::Adapters::ActiveRecord
  36. def get(id)
  37. return unless object = scoped.where(primary_key => id).first
  38. AbstractObject.new object
  39. end
  40. def scoped
  41. model.unscoped
  42. end
  43. end
  44.  
  45. module RailsAdminFindUnscopedPatch
  46. def get(id)
  47. RailsAdmin::Adapters::Mongoid::AbstractObject.new(model.unscoped.find(id))
  48. rescue
  49. super
  50. end
  51. end
  52.  
  53. RailsAdmin::Adapters::Mongoid.prepend(RailsAdminFindUnscopedPatch)
Add Comment
Please, Sign In to add comment