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:
gem "rename"
to your Gemfilebundle
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:
application.rb
)In my case, for a Rails 5.1.6
app I had to edit the following files:
from
addresses)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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With