提交 e202c6c8 编写于 作者: P Pratik Naik

Move :with/:without check outside the method generated by validates_format_of

上级 cccb0e6b
......@@ -47,13 +47,13 @@ def validates_format_of(*attr_names)
raise ArgumentError, "A regular expression must be supplied as the :without option of the configuration hash"
end
validates_each(attr_names, configuration) do |record, attr_name, value|
if configuration[:with] && value.to_s !~ configuration[:with]
record.errors.add(attr_name, :invalid, :default => configuration[:message], :value => value)
if configuration[:with]
validates_each(attr_names, configuration) do |record, attr_name, value|
record.errors.add(attr_name, :invalid, :default => configuration[:message], :value => value) if value.to_s !~ configuration[:with]
end
if configuration[:without] && value.to_s =~ configuration[:without]
record.errors.add(attr_name, :invalid, :default => configuration[:message], :value => value)
elsif configuration[:without]
validates_each(attr_names, configuration) do |record, attr_name, value|
record.errors.add(attr_name, :invalid, :default => configuration[:message], :value => value) if value.to_s =~ configuration[:without]
end
end
end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册