Class: MoulinRouge::CanCan::Responder

Inherits:
Object
  • Object
show all
Defined in:
lib/moulin_rouge/cancan/responder.rb

Overview

A cleaner implementation of CanCan #load_and_authorize_resource method. Everytime you use the #respond_with method, send the given resources to check the authorizations.

Instance Method Summary collapse

Constructor Details

#initialize(controller, resources, options = {}) ⇒ Responder

< ActionController::Responder



7
8
9
10
# File 'lib/moulin_rouge/cancan/responder.rb', line 7

def initialize(controller, resources, options={})
  super
  @skip_authorization = options.delete(:skip_authorization)
end

Instance Method Details

#to_htmlObject



12
13
14
15
16
17
18
# File 'lib/moulin_rouge/cancan/responder.rb', line 12

def to_html
  resources.each do |resource|
    action = resources.last == resource ? controller.params[:action].to_sym : :show
    controller.authorize!(action, resource_class_or_instace(resource)) unless skip?(resource)
  end
  super # Continue through method chain
end