Development Tip

Rails 4 앱의 이름을 바꾸는 방법은 무엇입니까?

yourdevel 2020. 11. 25. 21:17
반응형

Rails 4 앱의 이름을 바꾸는 방법은 무엇입니까?


rails plugin install git://github.com/get/Rename.git Rails 3 앱의 이름 만 변경할 수 있습니다.

Rails 4 앱의 이름을 바꿀 수있는 gem이 있습니까?

그렇지 않은 경우 이름을 바꾸는 더 좋은 방법을 제안하십시오.


rails 4.1.x 이후로 애플리케이션의 이름을 바꾸고 싶다면 수정해야 할 파일은 다음 두 개뿐입니다 config/application.rb.

require File.expand_path('../boot', __FILE__)

require 'rails/all'

# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(*Rails.groups)

module YourApplicationName # <-- rename it here
   class Application < Rails::Application
     ...
   end
end

config/initializers/session_store.rb(선택 사항) :

# Be sure to restart your server when you modify this file.

Rails.application.config.session_store :cookie_store, key: '_your_application_name_session' # <-- rename the key

Rails 4.0.x의 경우 renamegem을 사용 하고 다음 명령을 실행할 수 있습니다 .

rails g rename:app_to New-Name

그러면 필요한 파일이 업데이트됩니다.

old/ (master)  › rails g rename:app_to new
Search and replace module in to...
    gsub  config.ru
    gsub  Gemfile
    gsub  Gemfile.lock
    gsub  Rakefile
    gsub  README.md
    gsub  config/application.rb
    gsub  config/boot.rb
    gsub  config/environment.rb
    gsub  config/environments/development.rb
    gsub  config/environments/production.rb
    gsub  config/environments/test.rb
    gsub  config/initializers/backtrace_silencers.rb
    gsub  config/initializers/filter_parameter_logging.rb
    gsub  config/initializers/inflections.rb
    gsub  config/initializers/load_class_extensions.rb
    gsub  config/initializers/mime_types.rb
    gsub  config/initializers/secret_token.rb
    gsub  config/initializers/session_store.rb
    gsub  config/initializers/update.rb
    gsub  config/initializers/wrap_parameters.rb
    gsub  config/routes.rb
    gsub  config/initializers/session_store.rb
Renaming references...
Renaming directory...Done!
New application path is '/Users/username/code/new'

더하다

gem 'rename' Gemfile로

그때

bundle install

그 후

rails g rename:app_to name_of_app

mongoid를 사용하는 경우 데이터베이스 이름을 config/mongoid.yml


두 가지 방법이 있습니다.

1 . 수동 (Rails 4.1.x의 경우)

응용 프로그램 이름에 대한 참조를 수동으로 찾아야합니다. 그리고 수동으로 변경해야합니다. 사용되는 일반적인 장소는 다음과 같습니다.

config/application.rb
config/environment.rb
config/environments/development.rb
config/environments/production.rb
config/environments/test.rb
config/initializers/secret_token.rb
config/initializers/session_store.rb
config/routes.rb
config.ru
    app/views/layouts/application.html.erb
Rakefile

2. 자동 (Rails 3 및 4.0.X의 경우)

Or you can use the rename gem and execute the following command:

rails g rename:app_to New-Name

For Rails 5

Require

  • config/application.rb change the module name

Optional

  • config/initializers/session_store.rb (in Rails.application.config.session_store) change the session name
  • app/views/layouts/application.html.erb You can change the <title>...</title>, if it is not already done

I just used this rename gem in a basic rails 4 app:

https://github.com/morshedalam/rename

This is quite a bit different to get's version.


Easy enough to use:

Add this to Gemfile:

gem 'rename'

And run:

rails g rename:app_to NewName

Seemed to the trick,
It also updated my rubymine .idea project settings :)


In Rails 4.2 just change in application config file

config/application.rb

and config/initializers/session_store.rb (optional):

Rails.application.config.session_store :cookie_store, key: '_your_application_name_session' # <-- rename the key

then restart your server.

That's it!


For rails 5.2

Add gem 'rename' to the gemfile

bundle install

rails g rename:into your_new_app_name


Here is a gem specifically for Rails 4 https://github.com/negativetwelve/rails-rename (I haven't used it but it seems fine)

The other gems listed here only target Rails 3


In Rails 5.x, doing it manually

using ag (https://github.com/ggreer/the_silver_searcher), there are files that use the default folder name (if generated via rails new .)

three basic files, relative to root of project, need to be updated:

  • config/cable.yml > channel_prefix:
  • config/environments/production.rb > # config.active_job.queue_name_prefix
  • package.json > name

There are sure to be more locations as mentioned previously such as database etc. Hope this helps.

참고URL : https://stackoverflow.com/questions/20988813/how-to-rename-rails-4-app

반응형