Created
May 29, 2011 07:51
-
-
Save danielevans/997550 to your computer and use it in GitHub Desktop.
multiple dynamic file storage for paperclip
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Paperclip | |
class Attachment | |
attr_accessor :queued_for_write, :queued_for_delete | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@attachment.instance.extra_files ||= [] | |
@attachment.instance.extra_files << File.join(File.dirname(@attachment.path), "special_output_file_name") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def queue_existing_for_delete | |
return unless file? | |
@queued_for_delete = [@queued_for_delete, instance.extra_files].flatten.compact.uniq | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
serialize :extra_files |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Paperclip | |
class Interpolations | |
alias :old_extension, :extension | |
def extension(attachment, style_name) | |
if it_is_one_of_the_special_files # this test depends on the situation | |
ext = File.extname(style_name) # rip off the extension | |
ext.slice! 0 | |
ext | |
else | |
old_extension | |
end | |
end | |
alias :old_style, :style | |
def style(attachment, style_name) | |
if it_is_one_of_the_special_files | |
File.basename(style_name, File.extname(style_name)) | |
else | |
old_style | |
end | |
end | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Paperclip | |
class MyProcessor < Processor | |
def make | |
Paperclip.run "yourfancyprocessor", "args" | |
@attachment.queued_for_write["special_output_file_name"] = File.open(File.join(File.dirname(@file.path), "special_output_file_name")) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment