Renaming Ruby on Rails application

前端 未结 6 1132
感情败类
感情败类 2020-12-05 10:34

Is there a way to rename the application in Rails 2?

相关标签:
6条回答
  • 2020-12-05 10:45

    Rails 2 doesn't really have a concept of an application 'name'. The only thing that identifies your app is the name of the folder itself.

    In Rails 3, it's a little different. Rails 3 projects are name-spaced to a module defined in config/application.rb. This application module is used to house your app, and you'll see it referenced by your config.ru, config/routes.rb, config/environment.rb and all the environments defined in config/environments/.

    If you were to open a terminal session and run the command rails new myapp, your config/application.rb file would define the module Myapp, inside which will be defined an Application class, which extends Rails::Application. All the other files will reference Myapp::Application.

    In both Rails 2 and 3, you will find a string key for your session defined in config/initializers/session_store.rb, which takes the default value of '_<myapp>_session'. It's not really tied to the "name" of your application, though you should try to keep it in sync to prevent any accidental session key name conflicts with other apps.

    0 讨论(0)
  • 2020-12-05 10:47

    I had some trouble renaming a Rails 3 app. I then found this plugin and it works like a charm.

    0 讨论(0)
  • 2020-12-05 10:56

    I've written the following script to do just that. You can see it also at https://gist.github.com/danielpclark/8dfcdd7ac63149323bbc

    #!/usr/bin/ruby
    # Rename Rails Project (File: rename_rails)
    # Copyright 6ft Dan(TM) / MIT License
    # Check the config/application.rb for capital usage in project name by model OldProjectName
    # Usage: rename_rails OldProjectName NewAwesomeName
    
    # Replace string instances of project name   
    `grep -lR #{ARGV[0]} | xargs sed -i 's/#{ARGV[0]}/#{ARGV[1]}/g'`
    `grep -lR #{ARGV[0].downcase} | xargs sed -i 's/#{ARGV[0].downcase}/#{ARGV[1].downcase}/g'`
    
    # Rename Rails directory if it exists
    if File.directory?(ARGV[0])
        `mv #{ARGV[0]} #{ARGV[1]}`
        drc = ARGV[1]
    elsif File.directory?(ARGV[0].downcase)
        `mv #{ARGV[0].downcase} #{ARGV[1]}`
        drc = ARGV[1]
    end
    
    # Delete temporary files (helps prevent errors)
    drc ||= ''
    if ['cache','pids','sessions','sockets'].all? {
            |direc| File.directory?(File.join(drc,'tmp', direc)) }
        FileUtils.rm_rf(File.join(drc,'tmp'))
    end
    

    And I've created a howto video on YouTube. http://youtu.be/dDw2RmczcDA

    0 讨论(0)
  • 2020-12-05 10:58

    You can use https://github.com/morshedalam/rename to rename Rails 3 application

    0 讨论(0)
  • 2020-12-05 11:02

    just rename the application directory, nothing more. I did it several times, no issues.

    0 讨论(0)
  • 2020-12-05 11:06

    Number of places in your files where your app must be renamed (Rails 3.1) or you will not be able to start your server. So do the following:

    1) Rename the directory

    2) Rename module (yourapp) in the Application.rb file.

    3) Rename (yourapp)::Application in the following files:

    environment.rb

    routes.rb

    config.ru

    Rakefile

    initializers/secret_token.rb

    initializers/session_store.rb

    environments/test.rb, production.rb and development.rb

    4) You can also rename the databases in config.database.yml.sqlite3 to (yourapp)_development, (yourapp)_test etc. It may be necessary reload your databases in this case. I used the yaml_db gem and rake db:reload to do this and worked.

    That should do it.

    0 讨论(0)
提交回复
热议问题