Activerecord activeuuid和rails 4.1.1兼容吗?或者这里有问题?

Activerecord activeuuid和rails 4.1.1兼容吗?或者这里有问题?,activerecord,rubygems,uuid,ruby-on-rails-4.1,Activerecord,Rubygems,Uuid,Ruby On Rails 4.1,下面是我试图用来实现gem的一个小代码片段: Gemfile 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的一个小代码片段:

Gemfile

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'
User.rb

class User < ActiveRecord::Base
  include ActiveUUID::UUID
end
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
class用户
迁移xxxxxxxxx\u创建用户。rb

class User < ActiveRecord::Base
  include ActiveUUID::UUID
end
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
class CreateUsersfalse do | t|
t、 uuid:id,:主键=>true
t、 字符串:电子邮件
t、 时间戳
结束
结束
def自动关闭
下拉列表:用户
结束
结束
即使在捆绑或重新启动控制台之后,在这里使用简单查询也证明不可行

 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:016>User.all
NoMethodError:User的未定义方法“set_primary_key”(调用“User.connection”以建立连接):类
来自/home/sahil/.rvm/gems/ruby-2.1。1@myapp/gems/activerecord-4.1.1/lib/active\u record/dynamic\u matchers.rb:26:in'method\u missing'
来自/home/sahil/.rvm/gems/ruby-2.1。1@myapp/gems/activeuuid-ps-0.1.2/lib/activeuuid/uuid.rb:54:in'block in'
来自/home/sahil/.rvm/gems/ruby-2.1。1@myapp/gems/activesupport-4.1.1/lib/active\u-support/concern.rb:120:in'class\u-eval'
来自/home/sahil/.rvm/gems/ruby-2.1。1@myapp/gems/activesupport-4.1.1/lib/active\u-support/concern.rb:120:in'append\u-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`'
from/home/sahil/projects/test_projects/myapp/app/models/user.rb:1:in`'
来自/home/sahil/.rvm/gems/ruby-2.1。1@myapp/gems/activesupport-4.1.1/lib/active\u-support/dependencies.rb:443:in'load'
来自/home/sahil/.rvm/gems/ruby-2.1。1@myapp/gems/activesupport-4.1.1/lib/active\u support/dependencies.rb:443:in`block in load\u file'
来自/home/sahil/.rvm/gems/ruby-2.1。1@myapp/gems/activesupport-4.1.1/lib/active\u-support/dependencies.rb:633:in'new\u-constants\u-in'
来自/home/sahil/.rvm/gems/ruby-2.1。1@myapp/gems/activesupport-4.1.1/lib/active\u-support/dependencies.rb:442:“加载文件”中的
来自/home/sahil/.rvm/gems/ruby-2.1。1@myapp/gems/activesupport-4.1.1/lib/active\u-support/dependencies.rb:342:in'require\u或\u-load'
来自/home/sahil/.rvm/gems/ruby-2.1。1@myapp/gems/activesupport-4.1.1/lib/active\u support/dependencies.rb:480:in'load\u missing\u constant'
来自/home/sahil/.rvm/gems/ruby-2.1。1@myapp/gems/activesupport-4.1.1/lib/active\u-support/dependencies.rb:180:in'const\u-missing'
起始(irb):16
来自/home/sahil/.rvm/gems/ruby-2.1。1@myapp/gems/railties-4.1.1/lib/rails/commands/console.rb:90:in'start'
来自/home/sahil/.rvm/gems/ruby-2.1。1@myapp/gems/railties-4.1.1/lib/rails/commands/console.rb:9:in'start'
来自/home/sahil/.rvm/gems/ruby-2.1。1@myapp/gems/railties-4.1.1/lib/rails/commands/commands\u tasks.rb:69:in'console'
来自/home/sahil/.rvm/gems/ruby-2.1。1@myapp/gems/railties-4.1.1/lib/rails/commands/commands\u tasks.rb:40:in'run\u command!'
来自/home/sahil/.rvm/gems/ruby-2.1。1@myapp/gems/railties-4.1.1/lib/rails/commands.rb:17:in`'
从箱子/轨道:4:in“require”
从箱子/轨道:4:in`'
甚至

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>'
2.1.1:029>User.count
NoMethodError:User的未定义方法“set_primary_key”(调用“User.connection”以建立连接):类
来自/home/sahil/.rvm/gems/ruby-2.1。1@myapp/gems/activerecord-4.1.1/lib/active\u record/dynamic\u matchers.rb:26:in'method\u missing'
来自/home/sahil/.rvm/gems/ruby-2.1。1@myapp/gems/activeuuid-ps-0.1.2/lib/activeuuid/uuid.rb:54:in'block in'
..........
..........
从箱子/轨道:4:in“require”
从箱子/轨道:4:in`'

这里怎么了。我是否缺少一些必需的依赖项。

找到了一个更好的解决方案,并按如下所示实施: