Created
July 21, 2014 10:29
-
-
Save elle/4c048c08d07999374017 to your computer and use it in GitHub Desktop.
Safe attachments
This file contains 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
# in AttachmentsHelper: | |
def safe_attachment_path(attachment, size=nil) | |
retrieve_attachment_path(attachment.id, attachment.original_name, :size => size) | |
end | |
# and then have a route | |
match '/files/:id/:filename' => 'attachments#retrieve', :as => :retrieve_attachment | |
# and a controller action | |
def retrieve | |
path = params[:size] ? resource.file_url(params[:size]) : resource.file_url | |
redirect_to path | |
else | |
redirect_to back, :notice => 'Cannot find resource' | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment