33

Is the rename gem the best way to rename my rails 5 app?

Also, is there any notes I have to keep in mind when renaming my app?

3
  • 2
    This question has been asked multiple times before. Take a look at stackoverflow.com/questions/20988813/how-to-rename-rails-4-app Commented Feb 19, 2017 at 11:52
  • 1
    Thank you. So the solution for 4.1.x is the same for rails 5? Commented Feb 19, 2017 at 12:57
  • I'm not sure, but in my provided link above there is a section specifically for Rails 5. Commented Feb 19, 2017 at 15:34

4 Answers 4

34

Renaming your rails 5 app is even easier!

Open up the config/application.rb file within your rails project, there you see a module with the same name as your app. All you need to do is change the modules name to your preferred app name.

Besides that there are some other references to the old app name, but changing them is not required. Check out config/initializers/session_store.rb for example, where the session cookies name still uses the old app name. But the good old 'Find all' function in your IDE/editor can probably help you with these references.

Sign up to request clarification or add additional context in comments.

Comments

12

The following worked for me:

  1. Add gem "rename" to your Gemfile
  2. bundle
  3. rails g rename:into NEW_NAME

Note that this will create a new folder with the new app name, move all the files to the new folder and remove the old app. So take a back if you need to. The files that are modified are:

gsub Gemfile.lock gsub Gemfile gsub config.ru gsub README.md gsub package.json gsub Rakefile gsub config/puma.rb gsub config/environments/production.rb gsub config/environments/test.rb gsub config/environments/development.rb gsub config/routes.rb gsub config/initializers/assets.rb gsub config/initializers/cookies_serializer.rb gsub config/initializers/content_security_policy.rb gsub config/initializers/application_controller_renderer.rb gsub config/initializers/wrap_parameters.rb gsub config/initializers/mime_types.rb gsub config/initializers/backtrace_silencers.rb gsub config/initializers/filter_parameter_logging.rb gsub config/initializers/inflections.rb gsub config/application.rb gsub config/spring.rb gsub config/boot.rb gsub config/environment.rb gsub config/initializers/session_store.rb 

More info here: http://www.adamscott.io/blog/2014/01/21/renaming-a-ruby-on-rails-application

Comments

5

With the most popular text editors and IDEs you can search for a string across all project files. If by any chance you are using Sublime Text, you can do it with the keyboard shortcut Ctrl++F or using Find > Find in files, as explained here.

Remember that your app name might appear in the following formats:

  • MyAppName (in application.rb)
  • my-app-name
  • my_app_name
  • My App Name (in layouts)

In my case, for a Rails 5.1.6 app I had to edit the following files:

  • config/application.rb
  • config/cable.yml
  • config/database.yml (if you want to change database names)
  • config/environments/production.rb
  • app/views/layouts/application.html.erb
  • package.json
  • app/mailers/* (change email from addresses)
  • config/initializers/devise.rb (config.mailer_sender)

2 Comments

text editors do not have a concept of "project files"
This can work better with regex. Assuming that your project name is Test Web, Ctrl + Shift + F, Turn on Regular Expressions, Turn off Case Sensitive, In Find field type: test(-|_| |)web, In Where field type: -tmp/,-log/, Press Find button. The last one is to exclude tmp/ and log/ folders.
4

A 'find and replace' approach is risky because it could break urls or routes.

Instead, add gem 'rename' to your gemfile, and run bundle install

Then simply:

rails g rename:into your_new_app_name

Comments