나는 Paperclip을 사용하여 일반 텍스트 파일을 업로드하는 작은 응용 프로그램을 만들고 있습니다. 문서 첨부 파일이있는 Upload
모델이 있습니다. 업로드 된 파일의 이름을 Upload.title
과 같도록 이름을 바꾸고 싶습니다.파일 이름 db/실제 불일치에 대한 종이 클립 보간
저는이를 위해 Paperclip 보간법을 사용했습니다.
#config/initializers/paperclip.rb
Paperclip.interpolates('upload_title') do |attachment, style|
attachment.instance.title.parameterize
end
#app/models/upload.rb
has_attached_file :document,
:url => "/:attachment/:id/:upload_title.:extension",
:path => ":rails_root/public/:attachment/:id/:upload_title.:extension"
그러나 파일 자체의 이름은 바뀌지 만 데이터베이스의 document_file_name
은 그대로 유지됩니다.
내가 새로운 Upload
을 만들 GitHub를하고 파일 "Original File Name.txt
"
garethrees.co.uk/misc/new.JPG을 첨부 업로드 한
새로 만든 Upload
이 여전히 원본 파일 이름으로 생성 된 것을 볼 수 있습니다.
또한 데이터베이스에 garethrees.co.uk/misc/created.JPG는 document_file_name
는 그것이로 동일하게 유지됩니다.
garethrees.co.uk/misc/db.JPG
그러나, 실제 파일 시스템에서 문서 개명이다.
garethrees.co.uk/misc/finder.JPG는
난 정말이 파일을 다운로드하는 사용자를 위해 종이 클립 경로를 사용할 필요로 맞게 모두 기록해야합니다.
감사
좋은 아이디어. 내가 Paperclip에 고유 한 솔루션을 찾지 못하면 그것을 사용할 것입니다. 감사! – ghr