Class: Para::ControllerResource

Inherits:
CanCan::ControllerResource
  • Object
show all
Defined in:
lib/para/controller_resource.rb

Instance Method Summary collapse

Instance Method Details

#assign_attributes(resource) ⇒ Object

Todo : Document why this extension was added ?



4
5
6
7
8
9
10
11
12
13
14
# File 'lib/para/controller_resource.rb', line 4

def assign_attributes(resource)
  if @options[:singleton] && parent_resource && resource.respond_to?(:"#{ parent_name }=")
    resource.send(:"#{ parent_name }=", parent_resource)
  end

  initial_attributes.each do |attr_name, value|
    resource.send(:"#{ attr_name }=", value)
  end

  resource
end

#build_resourceObject

Remove automatic params assignation and let our controllers do it manually, letting our attribute fields to parse the params with a reference to the current resource.

Before this override, some attribute fields raised during #parse_input because of the controller resource that was missing at the time it was called (during the resource instanciation …)



24
25
26
27
28
29
30
31
32
# File 'lib/para/controller_resource.rb', line 24

def build_resource
  resource = resource_base.new

  unless @options[:bypass_params_assignation]
    resource.assign_attributes(resource_params || {})
  end

  assign_attributes(resource)
end