How to run a local Rails script on Heroku

From time to time, you may want to run some local Rails script on your Heroku app, and fortunately, you can do it easily with heroku run command.

To run a local Rails script, you need to piped script content into heroku run command, which actually runs rails runner command with - parameter, which by-turn mean to run the Ruby script read from stdin after loading the app:

$ cat rails_script.rb | heroku run "rails runner -"

To run some simple Ruby code next command could be used:

$ heroku run "rails runner 'Some.ruby(code)'"

P.S.

This tiny post was inspired by Run a Local Rails Script on Heroku post, which proposes to do the same but with rails console command. This solution also works, but as for me, use undesirable command for it.