Ruby-on-rails 在生产中运行 Rails 控制台

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15142752/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 21:30:16  来源:igfitidea点击:

running Rails console in production

ruby-on-rails

提问by nFinIt_loop

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:

我刚刚开始使用我的第一个 Rails 站点,但现在我遇到了问题。当我在 IDE 上以开发模式运行项目时,我可以将控制台运行到以下内容:

User.first.name='whatever'to change a users name.

User.first.name='whatever'更改用户名。

How do I accomplish the same task on a live site in production mode?

如何在生产模式的实时站点上完成相同的任务?

回答by Peter Berg

if you're running rails 3.0 or greater, you can also use

如果您运行的是 rails 3.0 或更高版本,您还可以使用

rails console production

production can of course be substituted with developmentor test(value is developmentby default)

生产当然可以用development或代替testdevelopment默认值为)

Adding the option --sandboxmakes it so that any changes you make to your database in the console will be rolled back after you exit

添加该选项后--sandbox,您在控制台中对数据库所做的任何更改都将在您退出后回滚

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"

如果您确实尝试在生产服务器上运行 rails 控制台,请尝试使用谷歌搜索“运行 rails 控制台 [您的云托管提供商]”,例如“运行 rails 控制台 heroku”

As of Rails 6 you need to use

从 Rails 6 开始,您需要使用

RAILS_ENV=production bundle exec rails c

or

或者

RAILS_ENV=production rails c

depending on your setup

取决于您的设置

回答by boulder

Pretty easy:

挺容易:

RAILS_ENV=production rails console

回答by RNickMcCandless

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 应用程序的 webroot 中。也就是说,如果您尚未在服务器上直接安装 rails 包,或者您想在 Web 应用程序的上下文中运行控制台。

回答by Pratap

Try below command.

试试下面的命令。

  rails c -e production

回答by jason328

Note: This answer assumes you are using Heroku as your hosting service.

注意:此答案假设您使用 Heroku 作为您的托管服务。

It depends on what hosting service you are using. For Heroku, you can go to your terminal and type in

这取决于您使用的托管服务。对于 Heroku,您可以转到终端并输入

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.

这将为您的生产站点加载 rails 控制台,并允许您为您的实时站点创建记录。

You can also look into seeding a databasebut that is generally meant for testing. RailsCasts has some videos on the topic but they are a bit outdated.

您还可以考虑为数据库播种,但这通常用于测试。RailsCasts 有一些关于这个主题的视频,但它们有点过时了。

回答by daniel0318

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

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

回答by Kapidis

The "bundle/exec rails c" command works too

“bundle/exec rails c”命令也有效