sending a command to heroku console - ruby-on-rails

What's the correct way of sending a command to heroku console on Cedar?
heroku console 2+2 works on older stacks - it warns me to use heroku run console on cedar.
When I run
heroku run console 2+2
it loads the unwanted "2+2" environment and opens up a console.
Loading 2+2 environment (Rails 3.2.3)
irb(main):001:0>
So what's the proper way of sending a command to heroku console on Cedar?

It's not the prettiest solution, but piping the command in did work.
echo "2 + 2" | heroku run console
Looking at the code, it appears there is no (current) built in way to do it.

Related

rails console in not accepting the commands

Rails console is loading but not accepting any commands .I am unable to even close the console by typing the exit command.
Loading development environment (Rails 7.0.2.4)
irb(main):001:0> ^C
irb(main):001:0> ^C
irb(main):001:0>
I have ruby 3.1.3p185 (2022-11-24 revision 1a6b16756e) [x64-mingw-ucrt] version
Typing exit and pressing Enter will exit the console.
irb(main):001:0> exit
IRB pocket reference here which may help: https://www.oreilly.com/library/view/ruby-pocket-reference/9780596514815/ch01s27.html
Looks like you're typing ctrl+C, which will cancel a process that is currently running. To exit the console type ctrl+D
There could be some environment issues as well, like if the environment is not correctly set up then the console may not work as expected or you can also try to specify the environment using the command rails console production or rails console development
& also try to check the database.yml there could be some issue there as well

rails: heroku run console giving error "bash: console: command not found"

Using the cedar-14 stack on Heroku. Just noticed that I can no longer run heroku run console because I get the error:
bash: console: command not found
I can still get to the console by calling:
heroku run bundle exec rails console
But I'm wondering what might have caused this change. I only noticed the issue after several days of commits so I can pinpoint the issue.
You need to use
heroku run rails console
The Basics for Heroku are explained under Heroku Devcenter.
Try
heroku run /app/bin/rails console
I happened to see this problem for a preview apps. For regular apps heroku console works.
I run into the same problem but I have resolved it by removing heroku/metrics build pack.
I have followed the configuration given for Ruby Language Metrics https://devcenter.heroku.com/articles/language-runtime-metrics-ruby and then tried to run the command heroku run console and it was triggering command not found error then I have reverted my changes and it started working.
Hope this will be helpful!

Heroku rails console does not start any more

I have an issue with running the rails console at heroku (cedar-stack). Each of the following commands heroku run console, heroku run rails console, heroku run bundle exec rails console results in the following error-message:
Running bundle exec rails console attached to terminal... up, run.8155
Abort testing: Your Rails environment is running in production mode!
This error-message is a little bit confused. What kind of test tries heroku to start? I just want to fire up the console, which had worked fine 4 weeks ago.
For Cedar Stack and later:
heroku run rails console --app <app name>
Previous stacks could use this command:
heroku run console --app <app name>
If you have multiple environments (staging / production / etc) you need this command:
heroku run -a app-name console
If you only have a single environment and never setup staging or other environments you can just run:
heroku run console
https://github.com/nemrow/rails_app_cheatsheet/blob/master/heroku.rdoc
For some reason you need to explicitly define the console process in the Procfile:
# Procfile
web: script/rails server -p $PORT
console: script/rails console
This blog post has more details: http://platypus.belighted.com/blog/2013/01/21/ruby-2-rails-4-heroku/
I was with the same problem and I decided to do this and it worked
$ heroku run bash
$ cd bin
~/bin $ ruby rails console
You should just use heroku run console as others have answered.
Heroku only runs in one environment at a time, which is configured by the RAILS_ENV and RACK_ENV environments variables.
When you connect, the console will use the correct environment automatically.

Running Rails console on heroku, in sandbox mode

Couldn't find it in the docs, nor on SO, but is there a way to run the Rails (3.2.x) console in sandbox mode on heroku (Celadon Cedar), equivalent to
rails console --sandbox
For a more "the Heroku way" alternative, heroku run console --sandbox does the trick as well:
$ heroku run console --sandbox
Running `console --sandbox` attached to terminal... up, run.6024
[...]
Loading production environment in sandbox (Rails 3.2.12)
Any modifications you make will be rolled back on exit
irb(main):001:0>

Heroku rails error trying to bring up console - sh: rails: not found

Trying to run the Heroku console but I am getting this following:
heroku run console
Running console attached to terminal... up, run.1
sh: console: not found
$ heroku run bash works but I seem to get a (green) bash prompt - "~ $" not a rails console! Can I get into the console from here?
fyi
git push heroku v311
Everything up-to-date
The first error is thrown simply because the console command doesn't exist. I personally have never meet a command called console in my life.
The syntax is heroku run the_command_i_want_to_run. For example: heroku run irb or heroku run bash.
The second error: There's no Rakefile in your project root. Since heroku run rails console say that Rails wasn't found, my guess is that your project wasn't (well) deployed.
Make sure you've done git push heroku.
You may also need to check the logs: heroku logs.
a guess:
heroku run rails console
If you're on the Bamboo stack (older stack than Cedar), try:
heroku run script/rails console
This works for me and is the command recommended in Heroku docs.
I got confused by this too.
It's just
$ heroku run console
Do this
heroku run -a my-app script/rails console
Reference: https://devcenter.heroku.com/articles/console-bamboo

Resources