ショートバージョン(TLDR): 以下のdownload_fileスクリプトは、Rails 3.2.6では正常に機能しますが、Rails3.2.11では機能しません。
ロングバージョン:
以前はテキストファイルのダウンロード機能がうまく機能していましたが、アクションを試してみると、次のようになります。
This webpage is not found
No webpage was found for the web address: http://localhost:3000/file_download
Error 6 (net::ERR_FILE_NOT_FOUND): The file or directory could not be found.
私のroutes.rbには正しい/file_downloadルートが指定されています。Railsバージョンを3.2.11に移行する以外は何も変更していません。ダウンロード用のスクリプトも変更されていません。それはまだこれです:
def download_file
filename = 'my_memories.txt'
file = File.open(filename, 'w') # creates a new file and writes to it
current_user.memories.order('date DESC').each do |m|
# Write the date, like 1/21/2012 or 1/21/2012~
file.write m.date.strftime("%m/%d/%Y")
file.write '~' unless m.exact_date
file.write " #{m.note}" if m.note
file.puts
# Write the content
file.puts m.content
file.puts # extra enter
end
send_file file
file.close # important, or no writing will happen
File.delete(filename)
end
コンソールに表示されるエラーは次のとおりです。
ERROR Errno::ENOENT: No such file or directory - my_memories.txt
そして、RubyのFile.openで「そのようなファイルやディレクトリはありません-text.txt(Errno :: ENOENT)」というエラーが表示され、その解決策を試しましたが、うまくいきませんでした。別のエラーが発生します。
private method `puts' called for #<String:0x00000104551838>
私がやったら
puts Dir.pwd.
ファイルのダウンロードメソッドの開始時。
何がうまくいかない可能性がありますか?Railsのバージョンが変更されるまでは問題なく動作しました。
前もって感謝します。