铁路4中的内容加倍

时间:2013-10-27 14:50:43

标签: ruby-on-rails-4 ruby-2.0

Rails 4,Ruby 2

我想计算我网站上的下载量。

第一项任务有效:

def download_many # select checkboxes and make a zipfile out of it
require 'net/ftp'
... #open ftp connection and create zipfile

     params[:files].each do |filename|
       File.open("path/to/download_log.txt", "a"){|l| l << "#{params[:file]}\n"} 
       #getbinaryfile from ftp server and add to zipfile
     end #do

     #send zipfile to user
...
end #def

[:files]为我提供了一个包含文件名的数组。我在包含该名称的日志文件中添加了一个新行,以便为所有文件创建一个简单的计数器

然而

def download #download one file per directly clicking on it
require 'net/ftp'
... #open ftp connection

   File.open("path/to/download_log.txt", "a"){|l| l << "#{params[:file]}\n"} 

... #send file to user
end #def

不起作用。它将文件名添加两次! to download_log。 params [:file]是一个字符串的文件名。(只返回一次,我用puts params[:file]进行了测试)我知道我可以使用数据库存储我的统计信息。但遇到的行为让我感到困扰......

对此有何解释?我在哪里可以找到日志或提示以更接近问题?

0 个答案:

没有答案