Rename Rails App - for Rails v6

Rename rails app using a patched rename gem supporting Rails 6
Icons/chart bar
Used 21 times
Created by
R Richard Logwood

Before Running 
Close any open editors or IDEs to prevent cached files from being written

After Running
cd .. 
cd YourNewNameHere
bin/bundle remove rename

Confirm the changes before committing
# re-bundle after removing rename

# confirm changes
git diff 

* NOTE:  Forked from Rename Rails App in order to use rename gem patched for Rails 6
* NOTE: See rename gem patch details at pull request Add support for Rails

Run this command in your Rails app directory in the terminal:

rails app:template LOCATION=""
Template Source

Review the code before running this template on your machine.

# coding: utf-8
# Please peform the manual steps indicated at the end
# Note: tests on Ubuntu 20.04.2 LTS, haven't found a way to successfully
#       cd back to new parent, hence the commands listed at end must be run
#       manally
# TODO: Test on MacBook
# TODO: Find out if there is a way to force thor run into a new directory context

require 'pathname'
pn  =
old_dir = pn.basename
parent_dir = pn.dirname

chdir_error_regex = /No such file or directory @ dir_chdir - .*#{old_dir}/

name = ask("Enter new name for your Rails app:")

renamed_dir = "#{parent_dir}/#{name}"

puts "💎 Adding gem 'rename'"
# use patched rename gem that supports Rails 6
# see pull request
run "bin/bundle add rename --git --branch rails_6.1.3.1"

  rails_command "g rename:into #{name}"
rescue Exception => e
  if e.message =~ chdir_error_regex
    # ignore cd error that occurs on removed directory
    puts "ignoring error #{e.message}"
    raise e

puts "Completed rename"

puts "***\n*** Please run these commands manually:\n***\n"
puts "cd #{renamed_dir}"
puts "bin/bundle remove rename"
puts "bin/bundle"
puts "git status"
puts "git diff"


Sign up or Login to leave a comment.