简体   繁体   中英

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]" eg "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

挺容易:

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.

试试下面的命令。

  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

“bundle / exec rails c”命令也可以

今天在控制台中运行 rails 6 RAILS_ENV=production rails console

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM