What is the most effective, secure and easiest way to rename a Ruby on Rails 3 project?
Asked
Active
Viewed 2,777 times
3
-
Please improve your question by posting some [properly formatted](http://stackoverflow.com/editing-help) code you've applied to the problem, and all **relevant** error messages exactly as they appear. – Todd A. Jacobs Mar 23 '13 at 20:42
-
I'm not even sure what that actually means; what do you want to rename? – Dave Newton Mar 23 '13 at 21:37
-
3I don't think this question requires any additional information. When you create a project with `rails new projectname`, it affects the config in various ways. That is the project name. @Paulo wants to change it. – Jim Stewart Mar 23 '13 at 22:39
-
This is a duplicate of http://stackoverflow.com/q/3270373/ and http://stackoverflow.com/q/4383670/ – awendt Mar 23 '13 at 22:56
-
@JimStewart that's the question! – sonnuforevis Mar 24 '13 at 01:22
-
@awendt these questions talks about Ruby on Rail 2; mine, is about Rails 3 – sonnuforevis Mar 24 '13 at 01:23
-
I've created a howto video here http://youtu.be/dDw2RmczcDA – 6ft Dan May 25 '14 at 22:45
-
A better solution for Rails5 https://stackoverflow.com/questions/42326432/how-to-rename-a-rails-5-application – Shane G May 17 '20 at 21:44
1 Answers
5
There's a Rails plugin called Rename that does this. It hasn't been updated in 2 years, but it appears to mostly work. It screws up CamelCaseNames, but in a consistent way.
Optionally, just do a grep
like in my example, and change those files manually (see below for list of files).
$ 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
You'll need to rename the top-level directory yourself:
$ cd ..
$ mv ProjectToRename SomeNewName

Jim Stewart
- 16,964
- 5
- 69
- 89
-
what should i run first: the plugin or the grep command? note that i'm looking for a "smooth operation"... – sonnuforevis Mar 24 '13 at 01:25
-
`grep` doesn't change anything. It just searches. You don't have to run it at all. – Jim Stewart Mar 24 '13 at 02:03
-
A better solution for Rails5 https://stackoverflow.com/questions/42326432/how-to-rename-a-rails-5-application – Shane G May 17 '20 at 21:44