1

Rails 4.2是否提供了一个在现有应用程序中重新生成config/application.rb的命令?如何在Rails 4.2中重新生成config/application.rb?

我问的原因是想象一个Rails应用程序是rails new -ed没有--skip-test-unit选项。

然后在很晚的日子,这个应用程序切换到RSpec。如何config/application.rb重新生成,就好像--skip-test-unit选项最初提供给rails new ...

所有这将有效地要做的就是改变require陈述附近config/application.rb文件从顶部:

require 'rails/all' 

到:

require "rails" 
# Pick the frameworks you want: 
require "active_model/railtie" 
require "active_job/railtie" 
require "active_record/railtie" 
require "action_controller/railtie" 
require "action_mailer/railtie" 
require "action_view/railtie" 
require "sprockets/railtie" 
# require "rails/test_unit/railtie" 
+1

我还没有试过这个,但是你不能只是运行'rails new --skip-test-unit'到一个新的目录并且将'config/application.rb'复制到你现有的应用程序中? – 2015-03-08 17:55:08

+0

谢谢@iqnivek,是的,肯定会工作,并成为一个很好的解决方案。也许有些东西是更轻量级的解决方案。 – 2015-03-08 18:12:17

回答

3

删除现有config/application.rb,并在该目录上述项目根目录,运行rails new ...并带有所需选项,包括应用程序目录名称和--skip-test-unit选项--skip选项,这使已经存在的rails new ...跳过创建文件:

# Inside your-rails-app/ directory: 

# 1. Remove config/application.rb 
rm config/application.rb 

# 2. Move up one directory 
cd .. 

# 3. Regenerate rails application with the --skip 
# option, using the name of your-rails-app. The 
# --skip option will not generate files that 
# already exist. 
#  
# This assumes you have rails installed as a global 
# gem, of the version given in the command (version 
# x.y.z in this case, replace with the version of Rails 
# your app uses, e.g. 4.2.88): 
rails _x.y.z_ new your-rails-app --skip --skip-test-unit 

# 4. Run git status to see if any files were unexpectedly added 
# (for example the README.rdoc file will be created 
# if it did not exist). 
git status 

# 5. Clean up and commit the changes you want. 

就是这样!