【发布时间】:2015-03-24 13:32:39
【问题描述】:
我想从我的数据库中提取一些信息到一个文本文件中。
有什么好的方法来做到这一点?我最初想运行我的 heroku bash 和 rails 控制台,因为我只需要做一个简单的循环来获取我需要的信息。但我不知道从heroku 写入文件的正确方法。它适用于我的本地 Rails 控制台
我试过了
File.open('text.txt', 'w') do |f|
User.all.each do |u|
f.puts u.email
end
end
或类似$stdout = File.new('/path/to/text.txt', 'w')
但我认为这些文件最终不会出现在我的本地目录中...
我该怎么做?
也欢迎其他简单的解决方案,因为我不认为我在做任何过于复杂的事情
尝试 Pakrash 的回答
在 heroku bash + rails c 中
我放了
require 'net/ftp'
ftp = Net::FTP.new('address.herokuapp.com','email@example.com', 'somepassword')
这只是挂起。没有错误..我必须 crl +c 退出它
我之前有我的完整地址https://adddress.herokuapp.com/,但上面写的是getaddrinfo: Name or service not known
我应该以不同的方式输入吗?
【问题讨论】:
标签: ruby-on-rails ruby bash heroku output