如何在 Rails 4.2 中重新生成 config/application.rb?
How to regenerate config/application.rb in Rails 4.2?
Rails 4.2 是否提供在现有应用程序中重新生成 config/application.rb
的单个命令?
我问的原因是想象一个 Rails 应用程序是 rails new
-ed 而没有 --skip-test-unit
选项。
然后在很久以后,这个应用程序切换到 RSpec。如何重新生成 config/application.rb
,就好像 --skip-test-unit
选项最初已提供给 rails new ...
?
有效的做法是将 config/application.rb
文件顶部附近的 require
语句更改为:
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"
删除现有的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.
就是这样!
Rails 4.2 是否提供在现有应用程序中重新生成 config/application.rb
的单个命令?
我问的原因是想象一个 Rails 应用程序是 rails new
-ed 而没有 --skip-test-unit
选项。
然后在很久以后,这个应用程序切换到 RSpec。如何重新生成 config/application.rb
,就好像 --skip-test-unit
选项最初已提供给 rails new ...
?
有效的做法是将 config/application.rb
文件顶部附近的 require
语句更改为:
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"
删除现有的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.
就是这样!