如何查看rails环境?

Ale*_*ack 34 ubuntu production ruby-on-rails

如何检查Ubuntu Server上的rails环境?

命令:Rails.env => command not found 命令: rails.env => command not found

Din*_*eic 74

如果您在app root中,请使用一个班轮

rails r"puts Rails.env"


Dav*_*son 15

听起来你试图Rails.env在shell中运行.这Rails.env是行不通的,因为是Ruby代码,而不是Unix shell命令.

您是如何在服务器上部署和启动rails应用程序的?Rails环境由服务器启动时RAILS_ENV环境变量的值决定.您可能在某处指定了某个配置文件,或者您可能只是使用表单命令启动服务器RAILS_ENV=production my_rails_server?我需要了解更多有关您运行启动服务器的命令的详细信息,以便真正回答这个问题.你在使用独角兽,杂种,Webrick还是别的什么?

  • 我想你可以在服务器上的`.bashrc`中输入以下命令:`export RAILS_ENV = production`.然后,当您在服务器上运行该命令时,您现在需要指定RAILS_ENV.但要小心; 如果你在服务器上键入`rake`它可能会在生产模式下运行你的测试,我不确定它是否会搞乱你的生产数据库. (3认同)

小智 10

您可以查看有关rails应用的完整详细信息.输入此命令"rake about".将为您提供有关您在机器上安装了哪个版本的ruby,rails版本等的简要详细信息.例如 -

关于您的应用程序的环境

Rails版本------> 4.2.6

Ruby版------> 2.3.1-p112(x86_64-linux)

RubyGems版本----> 2.5.1

机架版----> 1.6.4

JavaScript运行时-------> Node.js(V8)

中间件------> Rack :: Sendfile,ActionDispatch :: Static,

应用程序根目录---->/data/www/testapp

环境------>发展

数据库适配器-----> mysql2

数据库架构版本-----> 0


小智 7

在您的Rails应用程序目录中键入:

耙子


shi*_*ovk 6

rails r -e production 'p Rails.env'
production

rails r -e production 'p Rails.env.production?'
true

rails r 'p Rails.env'
development

rails r -e development 'p Rails.env.development?'
true

rails r -e test 'p Rails.env.test?'
true
Run Code Online (Sandbox Code Playgroud)

PS 如果 Railscommand not found尝试使用路径bin/

bin/rails r 'p Rails.env'
development
Run Code Online (Sandbox Code Playgroud)

PS2 如果使用rvm,检查安装的ruby版本:

rvm list

ruby-2.2.0 [ x86_64 ]
ruby-2.2.4 [ x86_64 ]
ruby-2.6.2 [ x86_64 ]
ruby-2.7.0 [ x86_64 ]
ruby-2.7.1 [ x86_64 ]
=> ruby-2.7.2 [ x86_64 ]
* ruby-2.7.3 [ x86_64 ]
ruby-3.0.0 [ x86_64 ]

# => - current
# =* - current && default
#  * - default
Run Code Online (Sandbox Code Playgroud)

选择版本:

rvm use ruby-3.0.0
Run Code Online (Sandbox Code Playgroud)

捆绑安装:

bundle
Run Code Online (Sandbox Code Playgroud)