1

config/application.rbRails 4.2 是否提供在现有应用程序中重新生成的单个命令?

我问的原因是想象一个 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"
4

1 回答 1

4

删除现有的,并在项目根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.

就是这样!

于 2015-05-21T16:51:46.067 回答