2015-06-21 42 views
0

我敢肯定,這個問題是由於這個gem看起來要3-4歲,並且rails改變了我們如何遷移的事實。但我對寶石/發電機不太熟悉。我試圖按照說明執行here中列出的說明。my_zipcode_gem遷移發生器不工作

rails g my_zipcode_gem:models 
rake db:migrate 
rake zipcodes:update 

然而,當我這樣做的第一步我最終得到這樣的:

/Users/thammond/.rvm/gems/ruby-2.1.1/gems/my_zipcode_gem-0.1.3/lib/generators/my_zipcode_gem/models_generator.rb:35:in `create_migration': wrong number of arguments (3 for 0) (ArgumentError) 
    from /Users/thammond/.rvm/gems/ruby-2.1.1/gems/railties-4.1.0/lib/rails/generators/migration.rb:63:in `migration_template' 
    from /Users/thammond/.rvm/gems/ruby-2.1.1/gems/my_zipcode_gem-0.1.3/lib/generators/my_zipcode_gem/models_generator.rb:36:in `create_migration' 
    from /Users/thammond/.rvm/gems/ruby-2.1.1/gems/thor-0.19.1/lib/thor/command.rb:27:in `run' 
    from /Users/thammond/.rvm/gems/ruby-2.1.1/gems/thor-0.19.1/lib/thor/invocation.rb:126:in `invoke_command' 
    from /Users/thammond/.rvm/gems/ruby-2.1.1/gems/thor-0.19.1/lib/thor/invocation.rb:133:in `block in invoke_all' 
    from /Users/thammond/.rvm/gems/ruby-2.1.1/gems/thor-0.19.1/lib/thor/invocation.rb:133:in `each' 
    from /Users/thammond/.rvm/gems/ruby-2.1.1/gems/thor-0.19.1/lib/thor/invocation.rb:133:in `map' 
    from /Users/thammond/.rvm/gems/ruby-2.1.1/gems/thor-0.19.1/lib/thor/invocation.rb:133:in `invoke_all' 
    from /Users/thammond/.rvm/gems/ruby-2.1.1/gems/thor-0.19.1/lib/thor/group.rb:232:in `dispatch' 
    from /Users/thammond/.rvm/gems/ruby-2.1.1/gems/thor-0.19.1/lib/thor/base.rb:440:in `start' 
    from /Users/thammond/.rvm/gems/ruby-2.1.1/gems/railties-4.1.0/lib/rails/generators.rb:157:in `invoke' 
    from /Users/thammond/.rvm/gems/ruby-2.1.1/gems/railties-4.1.0/lib/rails/commands/generate.rb:11:in `<top (required)>' 
    from /Users/thammond/.rvm/gems/ruby-2.1.1/gems/activesupport-4.1.0/lib/active_support/dependencies.rb:247:in `require' 
    from /Users/thammond/.rvm/gems/ruby-2.1.1/gems/activesupport-4.1.0/lib/active_support/dependencies.rb:247:in `block in require' 
    from /Users/thammond/.rvm/gems/ruby-2.1.1/gems/activesupport-4.1.0/lib/active_support/dependencies.rb:232:in `load_dependency' 
    from /Users/thammond/.rvm/gems/ruby-2.1.1/gems/activesupport-4.1.0/lib/active_support/dependencies.rb:247:in `require' 
    from /Users/thammond/.rvm/gems/ruby-2.1.1/gems/railties-4.1.0/lib/rails/commands/commands_tasks.rb:135:in `generate_or_destroy' 
    from /Users/thammond/.rvm/gems/ruby-2.1.1/gems/railties-4.1.0/lib/rails/commands/commands_tasks.rb:51:in `generate' 
    from /Users/thammond/.rvm/gems/ruby-2.1.1/gems/railties-4.1.0/lib/rails/commands/commands_tasks.rb:40:in `run_command!' 
    from /Users/thammond/.rvm/gems/ruby-2.1.1/gems/railties-4.1.0/lib/rails/commands.rb:17:in `<top (required)>' 
    from bin/rails:4:in `require' 
    from bin/rails:4:in `<main>' 

任何想法,我需要做的就是創業板的工作?它在我的應用程序中提供了我正在尋找的內容。

謝謝!

編輯:添加代碼生成:

module MyZipcodeGem 
    class ModelsGenerator < Base 
    include Rails::Generators::Migration 

    source_root File.expand_path('../templates', __FILE__) 

    def initialize(*args, &block) 
     super 
    end 

    def generate_models 
     # puts ">>> generate_zipcodes:" 
    end 

    def add_gems 
     add_gem "mocha", :group => :test 
    end 

    def create_models 
     template 'zipcode_model.rb', "app/models/zipcode.rb" 
     template 'county_model.rb', "app/models/county.rb" 
     template 'state_model.rb', "app/models/state.rb" 
    end 

    # Implement the required interface for Rails::Generators::Migration. 
    # taken from http://github.com/rails/rails/blob/master/activerecord/lib/generators/active_record.rb 
    def self.next_migration_number(dirname) 
     if ActiveRecord::Base.timestamped_migrations 
     Time.now.utc.strftime("%Y%m%d%H%M%S") 
     else 
     "%.3d" % (current_migration_number(dirname) + 1) 
     end 
    end 

    def create_migration 
     migration_template 'migration.rb', "db/migrate/create_my_zipcode_gem_models.rb" 
    end 

    def create_rakefile 
     template 'zipcodes.rake', "lib/tasks/zipcodes.rake" 
    end 

    end 
end 

# /Users/cblackburn/.rvm/gems/ruby-1.9.2-p136/gems/activerecord-3.0.3/lib/rails/generators/active_record/ 

回答

2

它看起來就像是調用使用不再需要的參數遷移。你有兩個選擇:

1)分叉代碼,更新它使用rails 4約定,並在github上創建一個pull請求。假設所有者仍然處於活動狀態,他們會將您的代碼帶入主服務器並重新發布該寶石。你將有助於支持社區,並在這個過程中感受良好。像我這樣的人有很多可以幫助你的人。

2)找到另一顆寶石做你想要的東西,比如http://www.rubygeocoder.com/我已經多次使用,並在做位置/郵編問題

+0

我想我會做兩個真棒 - 現在rubygeocoder,但我認爲把這顆寶石換回標準會很棒:) –