【问题标题】:Rails migration error with thumbs_up gemThumbs_up gem 的 Rails 迁移错误
【发布时间】:2014-04-23 17:18:24
【问题描述】:

我正在使用 thumbs_up gem 创建一个投票系统。我正在使用 PostgreSQL。当我跑步时:

rails generate thumbs_up

我收到以下错误:

/usr/local/rvm/gems/ruby-2.0.0-p247@firehose/gems/thumbs_up-0.6.7/lib/generators/thumbs_up/thumbs_up_generator.rb:21:in `create_migration': wrong number of arguments (3 for 0) (ArgumentError)
    from /usr/local/rvm/gems/ruby-2.0.0-p247@firehose/gems/railties-4.0.4/lib/rails/generators/migration.rb:65:in `migration_template'
    from /usr/local/rvm/gems/ruby-2.0.0-p247@firehose/gems/thumbs_up-0.6.7/lib/generators/thumbs_up/thumbs_up_generator.rb:22:in `create_migration'
    from /usr/local/rvm/gems/ruby-2.0.0-p247@firehose/gems/thor-0.19.1/lib/thor/command.rb:27:in `run'
    from /usr/local/rvm/gems/ruby-2.0.0-p247@firehose/gems/thor-0.19.1/lib/thor/invocation.rb:126:in `invoke_command'
    from /usr/local/rvm/gems/ruby-2.0.0-p247@firehose/gems/thor-0.19.1/lib/thor/invocation.rb:133:in `block in invoke_all'
    from /usr/local/rvm/gems/ruby-2.0.0-p247@firehose/gems/thor-0.19.1/lib/thor/invocation.rb:133:in `each'
    from /usr/local/rvm/gems/ruby-2.0.0-p247@firehose/gems/thor-0.19.1/lib/thor/invocation.rb:133:in `map'
    from /usr/local/rvm/gems/ruby-2.0.0-p247@firehose/gems/thor-0.19.1/lib/thor/invocation.rb:133:in `invoke_all'
    from /usr/local/rvm/gems/ruby-2.0.0-p247@firehose/gems/thor-0.19.1/lib/thor/group.rb:232:in `dispatch'
    from /usr/local/rvm/gems/ruby-2.0.0-p247@firehose/gems/thor-0.19.1/lib/thor/base.rb:440:in `start'
    from /usr/local/rvm/gems/ruby-2.0.0-p247@firehose/gems/railties-4.0.4/lib/rails/generators.rb:156:in `invoke'
    from /usr/local/rvm/gems/ruby-2.0.0-p247@firehose/gems/railties-4.0.4/lib/rails/commands/generate.rb:11:in `<top (required)>'
    from /usr/local/rvm/gems/ruby-2.0.0-p247@firehose/gems/activesupport-4.0.4/lib/active_support/dependencies.rb:229:in `require'
    from /usr/local/rvm/gems/ruby-2.0.0-p247@firehose/gems/activesupport-4.0.4/lib/active_support/dependencies.rb:229:in `block in require'
    from /usr/local/rvm/gems/ruby-2.0.0-p247@firehose/gems/activesupport-4.0.4/lib/active_support/dependencies.rb:214:in `load_dependency'
    from /usr/local/rvm/gems/ruby-2.0.0-p247@firehose/gems/activesupport-4.0.4/lib/active_support/dependencies.rb:229:in `require'
    from /usr/local/rvm/gems/ruby-2.0.0-p247@firehose/gems/railties-4.0.4/lib/rails/commands.rb:48:in `<top (required)>'
    from bin/rails:4:in `require'
    from bin/rails:4:in `<main>'

我该如何解决这个问题?

【问题讨论】:

  • 我得到了同样的错误。没有任何答案的运气。您是否安装了可投票的角色?您使用/尝试过什么版本的 gem?

标签: postgresql ruby-on-rails-4 rubygems


【解决方案1】:

这是 thumbs_up 中的一个错误。

在 github 上查看这个问题:https://github.com/bouchard/thumbs_up/issues/96

我偶然发现了同样的错误,并在上面的链接的帮助下修复了它。

显然,您所要做的就是更改 thumbs_up gem 中的一个文件(您会在错误本身中找到该 gem 的位置)。

在文件中 [path to gem]/lib/generators/thumbs_up/thumbs_up_generator.rb 替换

def create_migration
  migration_template 'migration.rb', File.join('db', 'migrate', 'thumbs_up_migration.rb')
end

def create_thumbs_up_migration
  migration_template 'migration.rb', File.join('db', 'migrate', 'thumbs_up_migration.rb')
end

【讨论】:

    【解决方案2】:

    在您的 Gemfile 中以这种方式要求 gem:

    gem 'thumbs_up', git: 'https://github.com/bouchard/thumbs_up.git', ref: 'f499a7c803c0a9fdcefe4275f2f0a10ca7964508'
    

    然后运行

    rails generate thumbs_up 
    

    这应该可行。为我工作-希望这会有所帮助....

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-28
      • 2015-04-04
      相关资源
      最近更新 更多