Ruby-on-rails Rails 如何在开发模式和生产模式之间切换?

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

Rails how to switch between dev and production mode?

ruby-on-railsrubyruby-on-rails-4

提问by Felix

How can I switch in Rails between the dev mode and the production mode?

如何在开发模式和生产模式之间切换 Rails?

and how can I deploy the database to production?

以及如何将数据库部署到生产环境?

回答by shinesecret

If you are using Rails 4.2 then you must know rails uses "spring" to make it faster. So in that case you can use following commands:

如果您使用的是 Rails 4.2,那么您必须知道 rails 使用“spring”来使其更快。因此,在这种情况下,您可以使用以下命令:

For Development just run

对于开发只需运行

Rails 4.2
    bin\rails s
Otherwise
   rails s

For Production just run

对于生产只需运行

Rails 4.2
    bin\rails s -e production
Otherwise    
    rails s -e production

To setup production database if database in production does not exist then run

如果生产中的数据库不存在,则设置生产数据库,然后运行

Rails 4.2
    bin/rake db:create db:migrate RAILS_ENV=production
Otherwise
    rake db:create db:migrate RAILS_ENV=production
    bundle exec rake db:create db:migrate RAILS_ENV=production

If DB already exists the:

如果数据库已经存在:

Rails 4.2
  bin/rake db:migrate RAILS_ENV=production
Otherwise
  rake db:migrate RAILS_ENV=production
  OR
  bundle exec rake db:migrate RAILS_ENV=production

Also if you want to stop spring or start spring then use following commands:

另外,如果您想停止弹簧或启动弹簧,请使用以下命令:

 bin/spring stop
 bin/spring start

回答by jon snow

Start server using -eoption.

使用-e选项启动服务器。

rails server -e production

And you can not deploy database. you needs migrations to run in production.

而且你不能部署数据库。您需要迁移才能在生产中运行。

回答by Stéphane

To start your server in development mode you only need to run rails sit will start your app in dev mode as well as your database.

要在开发模式下启动您的服务器,您只需要运行rails s它就会在开发模式下启动您的应用程序以及您的数据库。

To start your server in production mode you need to migrate your database with bundle exec rake db:migrate RAILS_ENV=productionand then start your server in production using rails s -e productionor RAILS_ENV=production rails s

要在生产模式下启动服务器,您需要使用以下命令迁移数据库,bundle exec rake db:migrate RAILS_ENV=production然后使用rails s -e production或在生产中启动服务器RAILS_ENV=production rails s

回答by Ali Akbar

In rails 5+ goto

在 Rails 5+ 中转到

config/puma.rb 

You can find the below line

您可以找到以下行

environment ENV.fetch("RAILS_ENV") { "development" }

change "development" to "production"

将“开发”改为“生产”