Commit f2b273a6 by Dan Collis-Puro

Refactor adding content_type errors to base attribute

parent 9aeb3331
...@@ -13,25 +13,28 @@ module Paperclip ...@@ -13,25 +13,28 @@ module Paperclip
return if (value.nil? && options[:allow_nil]) || (value.blank? && options[:allow_blank]) return if (value.nil? && options[:allow_nil]) || (value.blank? && options[:allow_blank])
validate_whitelist(record, base_attribute, attribute, value) validate_whitelist(record, attribute, value)
validate_blacklist(record, base_attribute, attribute, value) validate_blacklist(record, attribute, value)
if record.errors.include? attribute
record.errors.add base_attribute, record.errors[attribute]
end
end end
def validate_whitelist(record, base_attribute, attribute, value) def validate_whitelist(record, attribute, value)
if allowed_types.present? && allowed_types.none? { |type| type === value } if allowed_types.present? && allowed_types.none? { |type| type === value }
mark_invalid record, base_attribute, attribute, allowed_types mark_invalid record, attribute, allowed_types
end end
end end
def validate_blacklist(record, base_attribute, attribute, value) def validate_blacklist(record, attribute, value)
if forbidden_types.present? && forbidden_types.any? { |type| type === value } if forbidden_types.present? && forbidden_types.any? { |type| type === value }
mark_invalid record, base_attribute, attribute, forbidden_types mark_invalid record, attribute, forbidden_types
end end
end end
def mark_invalid(record, base_attribute, attribute, types) def mark_invalid(record, attribute, types)
record.errors.add attribute, :invalid, options.merge(:types => types.join(', ')) record.errors.add attribute, :invalid, options.merge(:types => types.join(', '))
record.errors.add base_attribute, :invalid, options.merge(:types => types.join(', '))
end end
def allowed_types def allowed_types
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment