Skip to content

Instantly share code, notes, and snippets.

@joshuap
Created June 18, 2013 18:38
Show Gist options
  • Save joshuap/5808063 to your computer and use it in GitHub Desktop.
Save joshuap/5808063 to your computer and use it in GitHub Desktop.
Define associations for eager loading when authorizing CanCan resources
module CanCanController
extend ActiveSupport::Concern
included do
extend(ClassMethods)
cattr_accessor :cancan_includes
self.cancan_includes = []
end
module ClassMethods
def cancan_resource_class
Class.new(super) do
protected
def resource_base
super.includes(@controller.class.cancan_includes)
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment