How to rename rails 5 application?

Is rename gem the best way to rename my rail 5?

Also, are there any notes that I should keep in mind when renaming my application?

+19
source share
4 answers

Renaming the rails 5 app is even easier!

Open the config/application.rb file in your rails project, there you will see a module with the same name as your application. All you have to do is change the module name to your preferred application name.

In addition, there are some other links to the old name of the application, but their change is not required. Take a look, for example, at config/initializers/session_store.rb , where the session cookie name still uses the old application name. But the old Find All feature in your IDE / editor can probably help you with these links.

+20
source

The following worked for me:

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

Note that this will create a new folder with a new application name, move all the files to the new folder, and delete the old application. So come back if you need to. Modified files:

 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 information here: http://www.adamscott.io/blog/2014/01/21/renaming-a-ruby-on-rails-application

+4
source

Using the most popular text editors and IDEs, you can search for a string in all project files. If you accidentally use Sublime Text, you can do this using the keyboard shortcut Ctrl + โ‡ง + F or using Find > Find in files , as described here .

Remember that the name of your application can be displayed in the following formats:

  • MyAppName (in application.rb )
  • my application name
  • my_app_name
  • The name of my application (in layouts)

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

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

The find and replace approach is dangerous because it can violate URLs or routes.

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

Then just:

rails g rename:into your_new_app_name

+1
source

Source: https://habr.com/ru/post/1015094/


All Articles