Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to rename a rails 5 application?

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.


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


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)

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