简体   繁体   English

Ruby on Rails中包含的不同环境

[英]Different environments included in Ruby on Rails

Can someone explain to me what the Rails environments are and what they do? 有人可以向我解释一下Rails环境是什么以及它们做什么吗? I have tried researching myself, but could not find anything. 我尝试研究自己,但找不到任何东西。 From what I gather, the environments are: 据我了解,这些环境是:

  • Development 发展
  • Productions 制作
  • Test 测试

Each "environment" is really just a config. 每个“环境”实际上只是一个配置。 You can launch your app in various different modes, and the modes are called "environments" because they affect the app's behaviour in lots of different ways. 您可以以各种不同的模式启动应用程序,这些模式称为“环境”,因为它们以许多不同的方式影响应用程序的行为。 Ultimately, though, they are just configs. 最终,尽管如此,它们只是配置。

BTW you can't have looked very hard when you looked "everywhere", because i just googled "rails environment" and the top result was this 顺便说一句,当您看到“无处不在”时,您可能不会显得很努力,因为我只是在“ rails environment”上进行了搜索,结果是

http://guides.rubyonrails.org/configuring.html http://guides.rubyonrails.org/configuring.html

which is the official explanation of configuring the rails environment. 这是配置rails环境的正式说明。

From what you have provided in your question, it seems that you are asking: 从您在问题中提供的内容来看,您似乎在问:

"What are the difference between each environment configuration in Rails?" “ Rails中每个环境配置之间有什么区别?”

Rails comes packages with 3 types of environments. Rails附带了3种类型的环境的软件包。 Each have its own server, database, and configuration. 每个都有自己的服务器,数据库和配置。 See Rails Guides: Configuration for more information on options available to you. 有关可用选项的更多信息,请参见《 Rails指南:配置 》。

Setting up the environment 搭建环境

To set your Rails environment, you will want to enter in command line: 要设置Rails环境,您需要在命令行中输入:

export RAILS_ENV=<env>

Where <env> can be test , development , or production . 可以testdevelopmentproduction <env>地方。 Setting this environment variable is crucial, as it will determine what gems are installed, or what env is touched when running rails console or rails server . 设置此环境变量至关重要,因为它将确定安装了什么gem,或者在运行rails consolerails server时触摸了什么环境。

Included in configuration is the gemset used for the app. 配置中包括用于该应用程序的gemset。 When you run rails new , you will find a Gemfile with groups test , development , and production . 当您运行rails new ,您将找到一个Gemfile,其中包含组testdevelopmentproduction These groups correspond to the environment currently set. 这些组对应于当前设置的环境。 When the environment is set to one of those, running bundle install installs all gems related to that group (and gems not listed in a group). 当环境设置为其中一种时,运行bundle install将安装与该组相关的所有gem(以及未在组中列出的gem)。

Included environments 包含环境

test is designed for running tests/specs. test旨在运行测试/规格。 This database will likely be bare bones, except for seeds you may call before running the suite. 该数据库很可能是空子,除了您在运行套件之前可以调用的种子之外。 After each test is complete, the database will rollback to its state before the test began. 每次测试完成后,数据库将回滚到测试开始之前的状态。 I do not recommend launching rails server , as running tests (via MiniTest or RSpec) will do this for you, and close the server once the suite is finished. 我不建议启动rails server ,因为运行测试(通过MiniTest或RSpec)将为您完成此操作,并在套件完成后关闭服务器。

development allows you to "test" your app with a larger database, typically a clone of production. development使您可以使用更大的数据库(通常是生产克隆)“测试”您的应用程序。 This allows you to test actual real-world data without breaking production (the version that customers or end-users will experience). 这样,您就可以在不中断生产(客户或最终用户将体验的版本)的情况下测试实际的实际数据。 To view the development environment in action, change the RAILS_ENV and launch rails server . 要查看实际的开发环境,请更改RAILS_ENV并启动rails server This is good for deciding how you want your pages to look (CSS, HTML). 这对于确定页面的外观(CSS,HTML)很有用。 It is also good practice to briefly "test" your app yourself, clicking around making sure everything "looks" good and the JavaScript works. 最好简短地自己“测试”您的应用程序,单击以确保一切看起来“不错”并且JavaScript可以正常运行。

production is reserved for the customer and end-user. production是为客户和最终用户保留的。 Configuration includes the actual domain of the app, which ports to use, and initializers or tasks to run. 配置包括应用程序的实际域,要使用的端口以及要运行的初始化程序或任务。 You do not want to play around with your database, as it may be customer-impacting. 您不想使用数据库,因为它可能会影响客户。 Ideally, the app should work as best as it can, since this is considered your "final product." 理想情况下,该应用程序应尽其所能,因为这被视为您的“最终产品”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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