DP_Hurley
DP_Hurley

Reputation: 21

Rename project in Ruby on Rails 4.0.2

I'm aware of the Rename plugin for rails (https://github.com/get/Rename), but does anyone know of a way to easily rename a project in Rails 4.0.2 seeing as plugins are deprecated beginning with Rails 4?

Upvotes: 2

Views: 573

Answers (4)

6ft Dan
6ft Dan

Reputation: 2445

I've written the following script to do just that. You can see it also at https://gist.github.com/danielpclark/8dfcdd7ac63149323bbc

#!/usr/bin/ruby
# Rename Rails Project (File: rename_rails)
# Copyright 6ft Dan(TM) / MIT License
# Check the config/application.rb for capital usage in project name by model OldProjectName
# Usage: rename_rails OldProjectName NewAwesomeName

# Replace string instances of project name   
`grep -lR #{ARGV[0]} | xargs sed -i 's/#{ARGV[0]}/#{ARGV[1]}/g'`
`grep -lR #{ARGV[0].downcase} | xargs sed -i 's/#{ARGV[0].downcase}/#{ARGV[1].downcase}/g'`

# Rename Rails directory if it exists
if File.directory?(ARGV[0])
    `mv #{ARGV[0]} #{ARGV[1]}`
    drc = ARGV[1]
elsif File.directory?(ARGV[0].downcase)
    `mv #{ARGV[0].downcase} #{ARGV[1]}`
    drc = ARGV[1]
end

# Delete temporary files (helps prevent errors)
drc ||= ''
if ['cache','pids','sessions','sockets'].all? {
        |direc| File.directory?(File.join(drc,'tmp', direc)) }
    FileUtils.rm_rf(File.join(drc,'tmp'))
end

And I've created a howto video on YouTube. http://youtu.be/dDw2RmczcDA

Upvotes: 0

Bijendra
Bijendra

Reputation: 10053

Just consider you have used

rails new blog

This will create a blog application. Now if you want to rename the folder blog, just use

$mv blog blog_new

This will just rename the folder and the application will run with no issues as external folder name changes will not affect the application. Else you need to change each file as specified by srt32 but i don't see any specific reason to change project name from inside.

Upvotes: 1

user3241004
user3241004

Reputation: 24

Enter following commands

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

Finally done.

You'll need to rename the top-level directory yourself:

$ cd ..
$ mv ProjectToRename SomeNewName

Upvotes: 0

srt32
srt32

Reputation: 1270

Assuming your app name is my_app you can run something like grep -r 'my_app' . from the root of your project and find all the places where the app name is referenced. It shouldn't be that bad to go update them. The list of places should look something like:

  • config/application.rb
  • config/environment.rb
  • config/environments/development.rb
  • config/environments/test.rb
  • config/environments/production.rb
  • config/initializers/secret_token.rb
  • config/routes.rb
  • Rakefile

Upvotes: 0

Related Questions