running Rails console in production
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.