可以在没有'heroku run console'的情况下在Heroku上运行单个Rails命令吗?

Mat*_*ham 6 ruby-on-rails heroku

我经常需要在Heroku上运行命令"Rails.cache.clear",我发现这样做的唯一方法是首先运行"heroku run console",然后运行命令.有没有办法一步到位?

小智 10

这似乎有效:

echo "Rails.cache.clear; exit" | heroku run console
Run Code Online (Sandbox Code Playgroud)

没有出口似乎因某种原因而挂起,至少对我而言.


Jon*_*ran 8

我想这就是你要找的东西:

heroku run rails runner -e production Rails.cache.clear
Run Code Online (Sandbox Code Playgroud)

如果未设置环境,将使用开发.

如果这是清除缓存等常见任务,请执行rake任务.

  • upvoted,但我从来不需要`-e production`,你在Heroku中所拥有的就是生产. (2认同)