Class: CanCan::ResourceAuthorization
- Inherits:
-
Object
- Object
- CanCan::ResourceAuthorization
- Defined in:
- lib/cancan/resource_authorization.rb
Overview
:nodoc:
Instance Attribute Summary collapse
-
#params ⇒ Object
readonly
Returns the value of attribute params.
Instance Method Summary collapse
- #authorize_resource ⇒ Object
-
#initialize(controller, params, options = {}) ⇒ ResourceAuthorization
constructor
A new instance of ResourceAuthorization.
- #load_and_authorize_resource ⇒ Object
- #load_resource ⇒ Object
Constructor Details
#initialize(controller, params, options = {}) ⇒ ResourceAuthorization
Returns a new instance of ResourceAuthorization.
5 6 7 8 9 |
# File 'lib/cancan/resource_authorization.rb', line 5 def initialize(controller, params, = {}) @controller = controller @params = params @options = end |
Instance Attribute Details
#params ⇒ Object (readonly)
Returns the value of attribute params.
3 4 5 |
# File 'lib/cancan/resource_authorization.rb', line 3 def params @params end |
Instance Method Details
#authorize_resource ⇒ Object
26 27 28 29 30 |
# File 'lib/cancan/resource_authorization.rb', line 26 def if @controller.cannot?(params[:action].to_sym, resource.model_instance || resource.model_class) @options[:message] ? @controller.(@options[:message]) : @controller. end end |
#load_and_authorize_resource ⇒ Object
11 12 13 14 |
# File 'lib/cancan/resource_authorization.rb', line 11 def load_resource end |
#load_resource ⇒ Object
16 17 18 19 20 21 22 23 24 |
# File 'lib/cancan/resource_authorization.rb', line 16 def load_resource unless collection_actions.include? params[:action].to_sym if new_actions.include? params[:action].to_sym resource.build(params[model_name.to_sym]) elsif params[:id] resource.find(params[:id]) end end end |