2

重命名 Ruby on Rails 3项目最有效、最安全最简单的方法是什么?

4

1 回答 1

5

有一个名为Rename的 Rails 插件可以做到这一点。它已经 2 年没有更新了,但它似乎大部分都可以工作。它搞砸了 CamelCaseNames,但以一致的方式。

或者,只需grep在我的示例中执行类似操作,然后手动更改这些文件(请参阅下面的文件列表)。

$ rails new ProjectToRename
$ cd ProjectToRename
$ grep -ri 'project_?to_?rename' .

./config/routes.rb:ProjectToRename::Application.routes.draw do
./config/application.rb:module ProjectToRename
./config/initializers/session_store.rb:ProjectToRename::Application.config.session_store :cookie_store, key: '_ProjectToRename_session'
./config/initializers/session_store.rb:# ProjectToRename::Application.config.session_store :active_record_store
./config/initializers/secret_token.rb:ProjectToRename::Application.config.secret_token = '69761de6e4534f0be37fbebee8e03f1e29d6935e12591444971bccc134503d390cb8b5587d7750a53cc428d3d57a5894437e4b148611623a7f0ff5048aeb4579'
./config/environment.rb:ProjectToRename::Application.initialize!
./config/environments/production.rb:ProjectToRename::Application.configure do
./config/environments/development.rb:ProjectToRename::Application.configure do
./config/environments/test.rb:ProjectToRename::Application.configure do
./app/views/layouts/application.html.erb:  <title>ProjectToRename</title>
./Rakefile:ProjectToRename::Application.load_tasks
./config.ru:run ProjectToRename::Application

$ rails plugin install git@github.com:get/Rename.git
$ rails g rename_to SomeNewName
$ grep -ri 'some_?new_?name' .

./config/routes.rb:Somenewname::Application.routes.draw do
./config/application.rb:module Somenewname
./config/initializers/session_store.rb:Somenewname::Application.config.session_store :cookie_store, key: '_ProjectToRename_session'
./config/initializers/session_store.rb:# Somenewname::Application.config.session_store :active_record_store
./config/initializers/secret_token.rb:Somenewname::Application.config.secret_token = '69761de6e4534f0be37fbebee8e03f1e29d6935e12591444971bccc134503d390cb8b5587d7750a53cc428d3d57a5894437e4b148611623a7f0ff5048aeb4579'
./config/environment.rb:Somenewname::Application.initialize!
./config/environments/production.rb:Somenewname::Application.configure do
./config/environments/development.rb:Somenewname::Application.configure do
./config/environments/test.rb:Somenewname::Application.configure do
./Rakefile:Somenewname::Application.load_tasks
./config.ru:run Somenewname::Application

您需要自己重命名顶级目录:

$ cd ..
$ mv ProjectToRename SomeNewName
于 2013-03-23T22:49:02.590 回答