【问题标题】:Is activeuuid and rails 4.1.1 compatible or there is something wrong here?activeuuid 和 rails 4.1.1 兼容还是这里有问题?
【发布时间】:2014-05-16 16:29:18
【问题描述】:

这是我试图用来实现 gem activeuuid 的小代码 sn-p:

宝石文件

source 'https://rubygems.org'
gem 'rails', '4.1.1'
gem 'pg'
gem 'sass-rails', '~> 4.0.3'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.0.0'
gem 'jquery-rails'
gem 'turbolinks'
gem 'jbuilder', '~> 2.0'
gem 'sdoc', '~> 0.4.0',          group: :doc
gem 'spring',        group: :development
gem 'activeuuid'

用户.rb

class User < ActiveRecord::Base
  include ActiveUUID::UUID
end

迁移xxxxxxxxx_create_users.rb

class CreateUsers < ActiveRecord::Migration
  def self.up
    create_table :users, :id => false  do |t|
      t.uuid :id, :primary_key => true
      t.string :email

      t.timestamps
    end
  end

  def self.down
    drop_table :users
  end

end

即使在捆绑或重新启动控制台之后,在这里使用一个简单的查询也是不可行的..

 2.1.1 :016 > User.all
    NoMethodError: undefined method `set_primary_key' for User (call 'User.connection' to establish a connection):Class
        from /home/sahil/.rvm/gems/ruby-2.1.1@myapp/gems/activerecord-4.1.1/lib/active_record/dynamic_matchers.rb:26:in `method_missing'
        from /home/sahil/.rvm/gems/ruby-2.1.1@myapp/gems/activeuuid-ps-0.1.2/lib/activeuuid/uuid.rb:54:in `block in <module:UUID>'
        from /home/sahil/.rvm/gems/ruby-2.1.1@myapp/gems/activesupport-4.1.1/lib/active_support/concern.rb:120:in `class_eval'
        from /home/sahil/.rvm/gems/ruby-2.1.1@myapp/gems/activesupport-4.1.1/lib/active_support/concern.rb:120:in `append_features'
        from /home/sahil/projects/test_projects/myapp/app/models/user.rb:3:in `include'
        from /home/sahil/projects/test_projects/myapp/app/models/user.rb:3:in `<class:User>'
        from /home/sahil/projects/test_projects/myapp/app/models/user.rb:1:in `<top (required)>'
        from /home/sahil/.rvm/gems/ruby-2.1.1@myapp/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:443:in `load'
        from /home/sahil/.rvm/gems/ruby-2.1.1@myapp/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:443:in `block in load_file'
        from /home/sahil/.rvm/gems/ruby-2.1.1@myapp/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:633:in `new_constants_in'
        from /home/sahil/.rvm/gems/ruby-2.1.1@myapp/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:442:in `load_file'
        from /home/sahil/.rvm/gems/ruby-2.1.1@myapp/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:342:in `require_or_load'
        from /home/sahil/.rvm/gems/ruby-2.1.1@myapp/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:480:in `load_missing_constant'
        from /home/sahil/.rvm/gems/ruby-2.1.1@myapp/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:180:in `const_missing'
        from (irb):16
        from /home/sahil/.rvm/gems/ruby-2.1.1@myapp/gems/railties-4.1.1/lib/rails/commands/console.rb:90:in `start'
        from /home/sahil/.rvm/gems/ruby-2.1.1@myapp/gems/railties-4.1.1/lib/rails/commands/console.rb:9:in `start'
        from /home/sahil/.rvm/gems/ruby-2.1.1@myapp/gems/railties-4.1.1/lib/rails/commands/commands_tasks.rb:69:in `console'
        from /home/sahil/.rvm/gems/ruby-2.1.1@myapp/gems/railties-4.1.1/lib/rails/commands/commands_tasks.rb:40:in `run_command!'
        from /home/sahil/.rvm/gems/ruby-2.1.1@myapp/gems/railties-4.1.1/lib/rails/commands.rb:17:in `<top (required)>'
        from bin/rails:4:in `require'
        from bin/rails:4:in `<main>'

甚至

2.1.1 :029 >   User.count
    NoMethodError: undefined method `set_primary_key' for User (call 'User.connection' to establish a connection):Class
        from /home/sahil/.rvm/gems/ruby-2.1.1@myapp/gems/activerecord-4.1.1/lib/active_record/dynamic_matchers.rb:26:in `method_missing'
        from /home/sahil/.rvm/gems/ruby-2.1.1@myapp/gems/activeuuid-ps-0.1.2/lib/activeuuid/uuid.rb:54:in `block in <module:UUID>'
        ..........
        ..........
        from bin/rails:4:in `require'
        from bin/rails:4:in `<main>'

这里出了什么问题。我是否缺少一些必需的依赖项。

【问题讨论】:

    标签: activerecord rubygems uuid ruby-on-rails-4.1


    【解决方案1】:

    【讨论】:

      猜你喜欢
      • 2014-07-25
      • 1970-01-01
      • 1970-01-01
      • 2013-03-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-10-31
      相关资源
      最近更新 更多