Renaming a Rails 3 app
Annoyingly Rails 3 spreads whatever name you give it when running ‘rails new’ over 10 or so files. This makes it hard to setup a base app. The following shell commands will change the name of the app to the new name:
find . -type f -print0 | xargs -0 perl -pi -e 's/Oldapp/Newapp/g'
find . -type f -print0 | xargs -0 perl -pi -e 's/oldapp/newapp/g'
find . -type f -print0 |
xargs -0 ruby -pi -e '$_.gsub(/Oldapp/, "Newapp")'
-e:1:in `gsub': invalid byte sequence in UTF-8 (ArgumentError)
from -e:1:in `<main>'
find . -type f -print0 |
xargs -0 ruby -pi -e '$_.force_encoding("UTF-8").gsub(/Oldapp/, "Newapp")'
Update:
While it’s nice to have a one liner that will accomplish the renaming. I’ve seen the above one liner corrupt the .git/index
I’ve written a simple ruby script that is more limited in how it selects the files: