From 1f81b8dd1e8255fb7b0499b1443a4d1fafcecfd7 Mon Sep 17 00:00:00 2001 From: Ryan Bates Date: Thu, 23 Sep 2010 11:58:55 -0700 Subject: [PATCH] use 'send' to access controller current_ability in case it's private --- CHANGELOG.rdoc | 4 ++-- lib/cancan/controller_resource.rb | 10 +++++++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.rdoc b/CHANGELOG.rdoc index 20f0a8f..f7b55dc 100644 --- a/CHANGELOG.rdoc +++ b/CHANGELOG.rdoc @@ -10,9 +10,9 @@ * Abilities can be defined with a string of SQL in addition to a block so accessible_by works with a block - see issue #150 -* Adding etter support for InheritedResource - see issue #23 +* Adding better support for InheritedResource - see issue #23 -* Loading the collection instance variable with accessible_by - see issue #137 +* Loading the collection instance variable (for index action) using accessible_by - see issue #137 * Adding action and subject variables to I18n unauthorized message - closes #142 diff --git a/lib/cancan/controller_resource.rb b/lib/cancan/controller_resource.rb index 3db00ba..91878c0 100644 --- a/lib/cancan/controller_resource.rb +++ b/lib/cancan/controller_resource.rb @@ -53,11 +53,11 @@ module CanCan def load_collection? resource_base.respond_to?(:accessible_by) && - !@controller.current_ability.has_block?(authorization_action, resource_class) + !current_ability.has_block?(authorization_action, resource_class) end def load_collection - resource_base.accessible_by(@controller.current_ability) + resource_base.accessible_by(current_ability) end def build_resource @@ -70,7 +70,7 @@ module CanCan end def initial_attributes - @controller.current_ability.attributes_for(@params[:action].to_sym, resource_class) + current_ability.attributes_for(@params[:action].to_sym, resource_class) end def find_resource @@ -156,6 +156,10 @@ module CanCan end end + def current_ability + @controller.send(:current_ability) + end + def name @name || name_from_controller end