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>
Related
I was trying to run my test cases on heroku.
Fund many blogs/answers telling how to run staging/custom environment on heroku.But whenever I run heroku run rspec spec/ it returns you are running production environment(not exact error).
So my qustion is not how to run staging/custom evironment on heroku but when I login into heroku rails console, I should be able to see
Rails.env #=> test
Or staging or whatever.
Any help is appreciable.
In heroku dashboard, you should just set RAILS_ENV and RACK_ENV to test.
You can do that here:
After setting these variables, I was able to start the console in test environment.
I have postgresql setup for my production schema in database.yml. I was able to successfully run RAILS_ENV=production rake db:migrate but when I do do RAILS_ENV=production rails console, it hangs. Never gives me the console prompt.
I've also tried bundle exec rails console production but didn't help.
Output:
Connecting to database specified by database.yml
...hangs after this.
Running rails 3.2.11 on ruby 2.1.2. I have rbenv and rbenv-gemsets installed.
To run the rails console in the production environment you need to pass the name of the environment after the command. The actual command is as follows.
rails console production
If that doesn't work, try restarting your PostgreSQL server and try again. It could be that you have crossed the number of possible connections with the PostgreSQL database.
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.
I have just gone live with my first Rails site, but now I have a problem. When I run the project in development mode on my IDE I can run the console to something like:
User.first.name='whatever' to change a users name.
How do I accomplish the same task on a live site in production mode?
if you're running rails 3.0 or greater, you can also use
rails console production
production can of course be substituted with development or test (value is development by default)
Adding the option --sandbox makes it so that any changes you make to your database in the console will be rolled back after you exit
If this isn't working for you, you may need to try
bundle exec rails console production
If you are actually trying to run the rails console on your production server, try googling "run rails console [your cloud hosting provider]" e.g. "run rails console heroku"
As of Rails 6 you need to use
RAILS_ENV=production bundle exec rails c
or
RAILS_ENV=production rails c
depending on your setup
Pretty easy:
RAILS_ENV=production rails console
If you have already deployed your site to the server, you can also use:
bundle exec rails console production
...in the webroot of your rails app. That is if you haven't installed the rails package directly on the server yet or if you want to run console within the context of your web app.
Try below command.
rails c -e production
Note: This answer assumes you are using Heroku as your hosting service.
It depends on what hosting service you are using. For Heroku, you can go to your terminal and type in
heroku run rails console
This will load up the rails console for your production site and will allow you to create records for your live site.
You can also look into seeding a database but that is generally meant for testing. RailsCasts has some videos on the topic but they are a bit outdated.
With Rails 6.1.6 on AlmaLinux8, the below command worked for me.
bundle exec rails console -e production
today with rails 6 run in console RAILS_ENV=production rails console
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.