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
...
@@ -203,6 +203,7 @@ module Paperclip
@styles
.
each
do
|
name
,
args
|
@styles
.
each
do
|
name
,
args
|
begin
begin
dimensions
,
format
=
args
dimensions
,
format
=
args
dimensions
=
dimensions
.
call
(
instance
)
if
dimensions
.
respond_to?
:call
@queued_for_write
[
name
]
=
Thumbnail
.
make
(
@queued_for_write
[
:original
],
@queued_for_write
[
name
]
=
Thumbnail
.
make
(
@queued_for_write
[
:original
],
dimensions
,
dimensions
,
format
,
format
,
...
...
tasks/paperclip_tasks.rake
View file @
c9834ef9
...
@@ -14,25 +14,42 @@ def obtain_attachments
...
@@ -14,25 +14,42 @@ def obtain_attachments
end
end
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
namespace
:paperclip
do
desc
"Regenerates thumbnails for a given CLASS (and optional ATTACHMENT)"
desc
"Regenerates thumbnails for a given CLASS (and optional ATTACHMENT)"
task
:refresh
=>
:environment
do
task
:refresh
=>
:environment
do
klass
=
obtain_class
for_all_attachments
do
|
instance
,
name
|
names
=
obtain_attachments
instance
.
send
(
name
).
reprocess!
instances
=
klass
.
find
(
:all
)
instance
.
send
(
name
).
save
end
puts
"Regenerating thumbnails for
#{
instances
.
length
}
instances of
#{
klass
.
name
}
:"
end
instances
.
each
do
|
instance
|
names
.
each
do
|
name
|
desc
"Cleans out invalid attachments. Useful after you've added new validations."
result
=
if
instance
.
send
(
"
#{
name
}
?"
)
task
:clean
=>
:environment
do
instance
.
send
(
name
).
reprocess!
for_all_attachments
do
|
instance
,
name
|
instance
.
send
(
name
).
save
if
instance
.
valid?
els
e
tru
e
tru
e
els
e
end
instance
.
send
(
"
#{
name
}
="
,
nil
)
print
result
?
"."
:
"x"
;
$stdout
.
flush
instance
.
save
end
end
end
end
puts
" Done."
end
end
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