load the collection instance variable on index action - closes #137
This commit is contained in:
@@ -221,6 +221,10 @@ module CanCan
|
||||
attributes
|
||||
end
|
||||
|
||||
def has_block?(action, subject)
|
||||
relevant_can_definitions(action, subject).any?(&:only_block?)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def unauthorized_message_keys(action, subject)
|
||||
|
||||
@@ -28,6 +28,8 @@ module CanCan
|
||||
def load_resource
|
||||
if !resource_instance && (parent? || member_action?)
|
||||
@controller.instance_variable_set("@#{instance_name}", load_resource_instance)
|
||||
elsif load_collection?
|
||||
@controller.instance_variable_set("@#{instance_name.pluralize}", load_collection)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -49,6 +51,16 @@ module CanCan
|
||||
end
|
||||
end
|
||||
|
||||
def load_collection?
|
||||
!parent? && collection_actions.include?(@params[:action].to_sym) &&
|
||||
resource_base.respond_to?(:accessible_by) &&
|
||||
!@controller.current_ability.has_block?(authorization_action, resource_class)
|
||||
end
|
||||
|
||||
def load_collection
|
||||
resource_base.accessible_by(@controller.current_ability)
|
||||
end
|
||||
|
||||
def build_resource
|
||||
resource = resource_base.send(@options[:singleton] ? "build_#{name}" : "new")
|
||||
initial_attributes.each do |name, value|
|
||||
|
||||
Reference in New Issue
Block a user