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

时间:2023-01-16 11:56:26

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

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

and how can I deploy the database to production?

如何将数据库部署到产品中呢?

3 个解决方案

#1


44  

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:

如果DB已经存在,则:

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:

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

 bin/spring stop
 bin/spring start

#2


8  

Start server using -e option.

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

rails server -e production

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

你不能部署数据库。在生产过程中需要迁移。

#3


3  

To start your server in development mode you only need to run rails s it 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=production and then start your server in production using rails s -e production or RAILS_ENV=production rails s

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

#1


44  

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:

如果DB已经存在,则:

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:

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

 bin/spring stop
 bin/spring start

#2


8  

Start server using -e option.

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

rails server -e production

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

你不能部署数据库。在生产过程中需要迁移。

#3


3  

To start your server in development mode you only need to run rails s it 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=production and then start your server in production using rails s -e production or RAILS_ENV=production rails s

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