113

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?

0

7 Answers 7

202

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

1
  • For anyone else stuck in the ice age of rails versions, for me in 2.3.2 it was script/console production Dec 28, 2020 at 21:27
59

Pretty easy:

RAILS_ENV=production rails console
0
23

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.

1
  • 1
    ...especially so in Rails 4.
    – IAmNaN
    Oct 2, 2013 at 3:21
8

Try below command.

  rails c -e production
0
6

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.

5

With Rails 6.1.6 on AlmaLinux8, the below command worked for me.

bundle exec rails console -e production
-1

today with rails 6 run in console RAILS_ENV=production rails console

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.