load the collection instance variable on index action - closes #137

This commit is contained in:
Ryan Bates
2010-09-07 16:25:02 -07:00
parent 158c908d3b
commit 9d915457af
4 changed files with 50 additions and 4 deletions

View File

@@ -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)

View File

@@ -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|