Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
paperclip
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ikcrm_common
paperclip
Commits
f2b273a6
Commit
f2b273a6
authored
Jun 21, 2013
by
Dan Collis-Puro
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor adding content_type errors to base attribute
parent
9aeb3331
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
8 deletions
+11
-8
lib/paperclip/validators/attachment_content_type_validator.rb
+11
-8
No files found.
lib/paperclip/validators/attachment_content_type_validator.rb
View file @
f2b273a6
...
...
@@ -13,25 +13,28 @@ module Paperclip
return
if
(
value
.
nil?
&&
options
[
:allow_nil
])
||
(
value
.
blank?
&&
options
[
:allow_blank
])
validate_whitelist
(
record
,
base_attribute
,
attribute
,
value
)
validate_blacklist
(
record
,
base_attribute
,
attribute
,
value
)
validate_whitelist
(
record
,
attribute
,
value
)
validate_blacklist
(
record
,
attribute
,
value
)
if
record
.
errors
.
include?
attribute
record
.
errors
.
add
base_attribute
,
record
.
errors
[
attribute
]
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
}
mark_invalid
record
,
base_attribute
,
attribute
,
allowed_types
mark_invalid
record
,
attribute
,
allowed_types
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
}
mark_invalid
record
,
base_attribute
,
attribute
,
forbidden_types
mark_invalid
record
,
attribute
,
forbidden_types
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
base_attribute
,
:invalid
,
options
.
merge
(
:types
=>
types
.
join
(
', '
))
end
def
allowed_types
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment