have params hash override initial attributes when building a new resource

This commit is contained in:
Ryan Bates
2010-09-03 14:11:44 -07:00
parent 721939babd
commit 7c5243321f
2 changed files with 17 additions and 14 deletions

View File

@@ -50,11 +50,11 @@ module CanCan
end
def build_resource
method_name = @options[:singleton] ? "build_#{name}" : "new"
resource = resource_base.send(*[method_name, @params[name]].compact)
resource = resource_base.send(@options[:singleton] ? "build_#{name}" : "new")
initial_attributes.each do |name, value|
resource.send("#{name}=", value)
end
resource.attributes = @params[name] if @params[name]
resource
end