disable_prefix_check.rb 674 B

12345678910111213141516171819202122
  1. module DisablePrefixCheck
  2. extend ActiveSupport::Concern
  3. module ClassMethods
  4. def check_prefix_options(options)
  5. end
  6. # `flexible = true` is hack to allow multiple things through the same AR class
  7. def conditional_prefix(resource, flexible = false)
  8. resource_id = "#{resource}_id".to_sym
  9. resource_type = flexible ? ":#{resource}" : resource.to_s.pluralize
  10. init_prefix_explicit resource_type, resource_id
  11. define_singleton_method :prefix do |options|
  12. resource_type = options[resource] if flexible
  13. options[resource_id].nil? ? "/admin/" : "/admin/#{resource_type}/#{options[resource_id]}/"
  14. end
  15. end
  16. end
  17. end