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
c9834ef9
Commit
c9834ef9
authored
Jul 08, 2008
by
Jon Yurek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added new task for cleaning out invalid attachments.
parent
13895667
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
15 deletions
+33
-15
lib/paperclip/attachment.rb
+1
-0
tasks/paperclip_tasks.rake
+32
-15
No files found.
lib/paperclip/attachment.rb
View file @
c9834ef9
...
...
@@ -203,6 +203,7 @@ module Paperclip
@styles
.
each
do
|
name
,
args
|
begin
dimensions
,
format
=
args
dimensions
=
dimensions
.
call
(
instance
)
if
dimensions
.
respond_to?
:call
@queued_for_write
[
name
]
=
Thumbnail
.
make
(
@queued_for_write
[
:original
],
dimensions
,
format
,
...
...
tasks/paperclip_tasks.rake
View file @
c9834ef9
...
...
@@ -14,25 +14,42 @@ def obtain_attachments
end
end
def
for_all_attachments
klass
=
obtain_class
names
=
obtain_attachments
instances
=
klass
.
find
(
:all
)
instances
.
each
do
|
instance
|
names
.
each
do
|
name
|
result
=
if
instance
.
send
(
"
#{
name
}
?"
)
yield
(
instance
,
name
)
else
true
end
print
result
?
"."
:
"x"
;
$stdout
.
flush
end
end
puts
" Done."
end
namespace
:paperclip
do
desc
"Regenerates thumbnails for a given CLASS (and optional ATTACHMENT)"
task
:refresh
=>
:environment
do
klass
=
obtain_class
names
=
obtain_attachments
instances
=
klass
.
find
(
:all
)
puts
"Regenerating thumbnails for
#{
instances
.
length
}
instances of
#{
klass
.
name
}
:"
instances
.
each
do
|
instance
|
names
.
each
do
|
name
|
result
=
if
instance
.
send
(
"
#{
name
}
?"
)
instance
.
send
(
name
).
reprocess!
instance
.
send
(
name
).
save
els
e
tru
e
end
print
result
?
"."
:
"x"
;
$stdout
.
flush
for_all_attachments
do
|
instance
,
name
|
instance
.
send
(
name
).
reprocess!
instance
.
send
(
name
).
save
end
end
desc
"Cleans out invalid attachments. Useful after you've added new validations."
task
:clean
=>
:environment
do
for_all_attachments
do
|
instance
,
name
|
if
instance
.
valid?
tru
e
els
e
instance
.
send
(
"
#{
name
}
="
,
nil
)
instance
.
save
end
end
puts
" Done."
end
end
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