adding :name option to load_and_authorize_resource if it does not match controller - closes #65
This commit is contained in:
parent
dfd84a10ed
commit
2a3dd85a18
|
@ -1,3 +1,5 @@
|
||||||
|
* Adding :name option to load_and_authorize_resource if it does not match controller - see issue #65
|
||||||
|
|
||||||
* Fixing issue when using accessible_by with nil can conditions (thanks jrallison) - see issue #66
|
* Fixing issue when using accessible_by with nil can conditions (thanks jrallison) - see issue #66
|
||||||
|
|
||||||
* Pluralize table name for belongs_to associations in can conditions hash (thanks logandk) - see issue #62
|
* Pluralize table name for belongs_to associations in can conditions hash (thanks logandk) - see issue #62
|
||||||
|
|
|
@ -59,6 +59,11 @@ module CanCan
|
||||||
#
|
#
|
||||||
# load_resource :nested => [:publisher, :author]
|
# load_resource :nested => [:publisher, :author]
|
||||||
#
|
#
|
||||||
|
# [:+name+]
|
||||||
|
# The name of the resource if it cannot be determined from controller (string or symbol).
|
||||||
|
#
|
||||||
|
# load_resource :name => :article
|
||||||
|
#
|
||||||
# [:+resource+]
|
# [:+resource+]
|
||||||
# The class to use for the model (string or constant).
|
# The class to use for the model (string or constant).
|
||||||
#
|
#
|
||||||
|
@ -102,6 +107,11 @@ module CanCan
|
||||||
# [:+except+]
|
# [:+except+]
|
||||||
# Does not apply before filter to given actions.
|
# Does not apply before filter to given actions.
|
||||||
#
|
#
|
||||||
|
# [:+name+]
|
||||||
|
# The name of the resource if it cannot be determined from controller (string or symbol).
|
||||||
|
#
|
||||||
|
# load_resource :name => :article
|
||||||
|
#
|
||||||
# [:+resource+]
|
# [:+resource+]
|
||||||
# The class to use for the model (string or constant). Alternatively pass a symbol
|
# The class to use for the model (string or constant). Alternatively pass a symbol
|
||||||
# to represent a resource which does not have a class.
|
# to represent a resource which does not have a class.
|
||||||
|
|
|
@ -54,7 +54,7 @@ module CanCan
|
||||||
end
|
end
|
||||||
|
|
||||||
def model_name
|
def model_name
|
||||||
@params[:controller].sub("Controller", "").underscore.split('/').last.singularize
|
@options[:name] || @params[:controller].sub("Controller", "").underscore.split('/').last.singularize
|
||||||
end
|
end
|
||||||
|
|
||||||
def collection_actions
|
def collection_actions
|
||||||
|
|
|
@ -114,4 +114,11 @@ describe CanCan::ResourceAuthorization do
|
||||||
authorization.load_resource
|
authorization.load_resource
|
||||||
@controller.instance_variable_get(:@ability).should == :some_resource
|
@controller.instance_variable_get(:@ability).should == :some_resource
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "should use :name option to determine resource name" do
|
||||||
|
stub(Ability).find(123) { :some_resource }
|
||||||
|
authorization = CanCan::ResourceAuthorization.new(@controller, {:controller => "foo", :action => "show", :id => 123}, {:name => :ability})
|
||||||
|
authorization.load_resource
|
||||||
|
@controller.instance_variable_get(:@ability).should == :some_resource
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue
Block a user