Fix NoMethodError

Raises NoMethodError when using ":singleton => true, :shallow => true" and parent_resource is nil
This commit is contained in:
Nanda Lopes
2010-11-04 02:47:02 +08:00
committed by Ryan Bates
parent cf263c105d
commit 9a7c427373
2 changed files with 21 additions and 2 deletions

View File

@@ -61,7 +61,11 @@ module CanCan
end
def build_resource
resource = resource_base.send(@options[:singleton] ? "build_#{name}" : "new")
if @options[:singleton] && resource_base.respond_to?("build_#{name}")
resource = resource_base.send("build_#{name}")
else
resource = resource_base.send("new")
end
initial_attributes.each do |name, value|
resource.send("#{name}=", value)
end
@@ -74,7 +78,7 @@ module CanCan
end
def find_resource
if @options[:singleton]
if @options[:singleton] && resource_base.respond_to?(name)
resource_base.send(name)
else
@options[:find_by] ? resource_base.send("find_by_#{@options[:find_by]}!", id_param) : resource_base.find(id_param)