提交 0801f6a3 编写于 作者: C Carlos Antonio da Silva

Refactor nested attributes limit logic to lookup :limit option only once

上级 bf27f6b2
......@@ -389,17 +389,19 @@ def assign_nested_attributes_for_collection_association(association_name, attrib
raise ArgumentError, "Hash or Array expected, got #{attributes_collection.class.name} (#{attributes_collection.inspect})"
end
limit = case options[:limit]
when Symbol
send(options[:limit])
when Proc
options[:limit].call
else
options[:limit]
end
if limit = options[:limit]
limit = case limit
when Symbol
send(limit)
when Proc
limit.call
else
limit
end
if limit && attributes_collection.size > limit
raise TooManyRecords, "Maximum #{limit} records are allowed. Got #{attributes_collection.size} records instead."
if limit && attributes_collection.size > limit
raise TooManyRecords, "Maximum #{limit} records are allowed. Got #{attributes_collection.size} records instead."
end
end
if attributes_collection.is_a? Hash
......@@ -438,7 +440,6 @@ def assign_nested_attributes_for_collection_association(association_name, attrib
else
association.add_to_target(existing_record)
end
end
if !call_reject_if(association_name, attributes)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册