How to change a Ruby on Rails application name?

前端 未结 8 1217
渐次进展
渐次进展 2020-11-30 19:33

I have a Ruby on Rails application that was created using:

rails new old_name -d mysql

Now I want to change the application name to be

相关标签:
8条回答
  • 2020-11-30 19:40

    You might find yourself having to rename the app when wanting or having to generate a model or scaffold with the same name as the app's name. Just happened to me. Used https://github.com/morshedalam/rename on Rails 3.2.13 and no problems so far.

    0 讨论(0)
  • 2020-11-30 19:43

    Run the following to replace the old_name for new_name from the root of your Rails (3.0.7) project.

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

    But be sure to run

    fgrep old_name . -iR
    

    Or something similar first to check if there are no occurrences of old_name in your project who not should be replaced.

    EDIT:

    Of course for this you need to have the replace command installed.

    And take in account that your appname will be CamelCased, so maybe you have to try a few different variations, like OldName vs. NewName.

    0 讨论(0)
  • 2020-11-30 19:45

    Rails 3 application can rename using https://github.com/morshedalam/rename

    0 讨论(0)
  • There's a Rails plugin to do it for you. Super convenient.

    https://github.com/get/rename

    0 讨论(0)
  • 2020-11-30 19:54

    To do this, I have used good old shell commands :

    grep -r old_name * | cut -d: -f1 | xargs sed -i .bak 's/old_name/new_name/g'
    

    This command replace the old_name with new_name in all file it finds the old_name. However, it creates a backup file with the extension '.bak'. Those file can be easily removed once you check everything went well.

    The advantage of this, is that it is not 'rails version dependent'.

    0 讨论(0)
  • 2020-11-30 19:55

    In Rails 3, there are references to the application name in the following files:

    • 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/mongoid.yml (if using Mongoid)
    • config/routes.rb
    • config.ru
    • Rakefile
    • app/views/layouts/application.html.erb, in title tag
    0 讨论(0)
提交回复
热议问题