Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

40 lines (32 sloc) 0.851 kB
module CanCan
class ControllerResource # :nodoc:
def initialize(controller, name, parent = nil)
@controller = controller
@name = name
@parent = parent
end
def model_class
@name.to_s.camelize.constantize
end
def find(id)
self.model_instance = base.find(id)
end
def build(attributes)
if base.kind_of? Class
self.model_instance = base.new(attributes)
else
self.model_instance = base.build(attributes)
end
end
def model_instance
@controller.instance_variable_get("@#{@name}")
end
def model_instance=(instance)
@controller.instance_variable_set("@#{@name}", instance)
end
private
def base
@parent ? @parent.model_instance.send(@name.to_s.pluralize) : model_class
end
end
end
Jump to Line
Something went wrong with that request. Please try again.