开发者

Renaming Ruby on Rails application

Is there a way to rename the application i开发者_运维知识库n Rails 2?


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


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.


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


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.


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


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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜