Skip to content

Instantly share code, notes, and snippets.

@elle
Created July 21, 2014 10:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elle/4c048c08d07999374017 to your computer and use it in GitHub Desktop.
Save elle/4c048c08d07999374017 to your computer and use it in GitHub Desktop.
Safe attachments
# 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