Ruby-on-rails 如何将rails更改为开发模式

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

how to change rails to development mode

ruby-on-railsrubyruby-on-rails-3

提问by Bick

In the documentation of rails (3.2.3) it says

在 rails (3.2.3) 的文档中,它说

In development mode (which is what you're working in by default), Rails reloads your application with every browser request, so there's no need to stop and restart the web server.

在开发模式下(这是您默认使用的模式),Rails 会在每次浏览器请求时重新加载您的应用程序,因此无需停止和重新启动 Web 服务器。

But clearly my app loads in production mode out of the box.(I can type Rails.env and see it).

但很明显,我的应用程序以生产模式加载开箱即用。(我可以输入 Rails.env 并查看它)。

Why?

为什么?

I then go to environment.rb and add

然后我去 environment.rb 并添加

ENV["RAILS_ENV"] = "development"

and still it is in production. Any idea?

它仍在生产中。任何的想法?

Edit : Here you go

编辑:给你

#Load the rails application
require File.expand_path('../application', __FILE__)

# Initialize the rails application
MyAppName::Application.initialize!

ENV["RAILS_ENV"] = "development"

回答by thesis

Possible solution for your situation could be:

您的情况可能的解决方案可能是:

rails server -e development

回答by Aldo 'xoen' Giambelluca

Though this is not a solution try to start the Rails server this way:

尽管这不是解决方案,但请尝试以这种方式启动 Rails 服务器:

RAILS_ENV=development bundle exec rails s

What do you see if put <%= Rails.env %>somewhere in you layout file?

如果放在<%= Rails.env %>布局文件的某个地方,你会看到什么?

回答by decider

If you are using Phusion Passenger, then add the following to your virtual host configuration file:

如果您使用 Phusion Passenger,请将以下内容添加到您的虚拟主机配置文件中:

   RailsEnv development

In other words, on my system, you would vim /etc/apache2/sites-available/[name of app] so that it looks like the following:

换句话说,在我的系统上,您将 vim /etc/apache2/sites-available/[应用程序名称] 使其看起来如下所示:

   <VirtualHost *>
   ServerName example.com
   DocumentRoot /home/yourname/htdocs/example.com/public
   RailsEnv development
   </VirtualHost>

You would then need to restart the web server:

然后,您需要重新启动 Web 服务器:

   sudo /etc/init.d/apache2 reload

Credit goes to: http://my.opera.com/williamn/blog/2009/03/03/how-to-make-phusion-passenger-run-in-development-mode

归功于:http: //my.opera.com/williamn/blog/2009/03/03/how-to-make-phusion-passenger-run-in-development-mode