Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Possible to run single Rails command on Heroku without 'heroku run console'?

I frequently need to run the command "Rails.cache.clear" on Heroku and the only way I have found to do it is to first run "heroku run console" and then run the command. Any way to do it in one step?

like image 498
Matt Fordham Avatar asked Oct 01 '12 18:10

Matt Fordham


People also ask

Which type of database Cannot be used to deploy your Rails app to Heroku?

So, the reason why you cannot use SQLite on Heroku is because SQLite stores all database information in a file on disk, and because Heroku will delete the files on your disk, this won't work.

How do I start rails console?

Go to your browser and open http://localhost:3000, you will see a basic Rails app running. You can also use the alias "s" to start the server: bin/rails s . The server can be run on a different port using the -p option. The default development environment can be changed using -e .


2 Answers

This seems to work:

echo "Rails.cache.clear; exit" | heroku run console

Without the exit it seems to hang for some reason, at least for me.

like image 80
Mitzimoto Avatar answered Oct 26 '22 10:10

Mitzimoto


I think this is what you're looking for:

heroku run rails runner -e production Rails.cache.clear

If you don't set the environment, development will be used.

If it's a common task like clearing the cache, make a rake task.

like image 34
Jonathan Tran Avatar answered Oct 26 '22 10:10

Jonathan Tran