Using the refile
gem, I have uploaded documents (.pdf, .docx, .pptx, etc.). Uploading is fine. When I use attachemnt_url
, it produces something like /attachments/...234jksdf2.../document
. When I click the link_to
, it downloads the document without an extension.
What's happening to make it operate this way? How can I restore my file type sanity?
This is what ended up being the correct solution for me.
link_to "Download file", attachment_url(@document, :file, format: @document.file_extension)
def file_extension
require 'rack/mime'
Rack::Mime::MIME_TYPES.invert[document_content_type].split('.').last
end