Ruby-on-rails 如何检查rails环境?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16249399/
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:53:16  来源:igfitidea点击:

How to check rails environment?

ruby-on-railsubuntuproduction

提问by Alexander Shlenchack

How check rails environment on Ubuntu Server?

如何检查 Ubuntu 服务器上的 rails 环境?

command: Rails.env => command not foundcommand: rails.env => command not found

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

回答by Dino Reic

One liner if you are in app root

如果您在应用程序根目录中,则为一个班轮

rails r "puts Rails.env"

rails r "放置 Rails.env"

回答by David Grayson

It sounds like you tried to run Rails.envin a shell. That won't work because Rails.envis Ruby code, not a Unix shell command.

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

How are you deploying and starting your rails app on the server? The Rails environment is determined by whatever the value of the RAILS_ENV environment variable is when the server starts. You might have some configuration file somewhere that specifies it, or maybe you just start your server with a command of the form RAILS_ENV=production my_rails_server? I would need to know more details about exactly what commands you run to start the server in order to really answer this. Are you using unicorn, mongrel, Webrick, or something else?

您如何在服务器上部署和启动 Rails 应用程序?Rails 环境由服务器启动时 RAILS_ENV 环境变量的值决定。您可能在某处有一些指定它的配置文件,或者您可能只是使用以下形式的命令启动服务器RAILS_ENV=production my_rails_server?为了真正回答这个问题,我需要了解有关您运行哪些命令来启动服务器的更多详细信息。你在使用独角兽、杂种、Webrick 还是其他东西?

回答by Rana Pratap Singh

You can check complete details about your rails app. By typing this command "rake about". Will give you brief details about which version of ruby have you installed on your machine, rails version etc. For example -

您可以查看有关 Rails 应用程序的完整详细信息。通过输入这个命令“rake about”。将为您提供有关您的机器上安装的 ruby​​ 版本、rails 版本等的简要详细信息。例如 -

About your application's environment

关于您的应用程序环境

Rails version ------> 4.2.6

Rails 版本 ------> 4.2.6

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

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

RubyGems version ----> 2.5.1

RubyGems 版本 ----> 2.5.1

Rack version ----> 1.6.4

机架版本----> 1.6.4

JavaScript Runtime -------> Node.js (V8)

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

Middleware ------> Rack::Sendfile, ActionDispatch::Static,

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

Application root ----> /data/www/testapp

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

Environment ------> development

环境------>开发

Database adapter -----> mysql2

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

Database schema version -----> 0

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

回答by Marcelo Campusano

On your Rails Application directory type :

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

rake about

回答by Galuga

You can also check your environment from your Rails console in the shell. Start at the application directory path.

您还可以从 shell 中的 Rails 控制台检查您的环境。从应用程序目录路径开始。

rails console<enter>

after you see the output from your console... (your output will most likely differ)

在您看到控制台的输出后...(您的输出很可能会有所不同)

Running via Spring preloader in process XXXXX
Loading development environment (Rails X.x.x)
irb(main):001:0>

At the promt type

在提示类型

Rails.env<enter>

Unless you have custom environments, one of the following environment is loaded

除非您有自定义环境,否则会加载以下环境之一

=> "development"
=> "production"
=> "test"