我想在生产中运行脚本。此脚本生成记录并将其插入生产数据库。我的问题是脚本试图将记录插入开发数据库。
run_report.rb
ENV['RAILS_ENV'] = 'production'
require 'rubygems'
require 'daemons'
Daemons.run('report.rb')
report.rb
ENV['RAILS_ENV'] = 'production'
...
@r = Report.new(:info => @info)
@r.save
我试过了: script / rails runner run_report.rb start
script / rails runner run_report.rb start production
答案 0 :(得分:6)
RAILS_ENV=production rails r script/foo.rb