怎么了?
我的朋友创建了一个rake任务来更新数据库中的数据(因为我们有db更改)。 以下是任务:
namespace :db do
task :update_database => :environment do
puts "Update do banco"
posts = Post.where("source_id is null").order("id")
done = Array.new
posts.each do |post|
if post.source_id.nil? and !done.include?(post)
posts2 = Post.where("content LIKE ? AND id != ?", post.content, post.id)
done.concat(posts2)
posts2.each do |post2|
post2.source_id = post.id
post2.save
end
end
end
end
end
我已经在我的localhost中执行了这个rake任务,但是我将我的项目部署到heroku,现在我的项目无法在线打开。我不记得执行rake任务的命令是什么,我无法在任何地方找到它。
我的问题是:
谢谢!
答案 0 :(得分:3)
heroku run bundle exec rake db:update_database
应该这样做。
bundle exec
确保脚本在当前bundle的上下文中运行。