1
這裏是我想用來實現寶石activeuuid一點的代碼片段:是activeuuid和rails 4.1.1兼容還是有問題?
的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
遷移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
Tyring一個簡單的查詢是不是證明是捆綁甚至或控制檯重新開始之後fisible這裏..
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/[email protected]/gems/activerecord-4.1.1/lib/active_record/dynamic_matchers.rb:26:in `method_missing'
from /home/sahil/.rvm/gems/[email protected]/gems/activeuuid-ps-0.1.2/lib/activeuuid/uuid.rb:54:in `block in <module:UUID>'
from /home/sahil/.rvm/gems/[email protected]/gems/activesupport-4.1.1/lib/active_support/concern.rb:120:in `class_eval'
from /home/sahil/.rvm/gems/[email protected]/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/[email protected]/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:443:in `load'
from /home/sahil/.rvm/gems/[email protected]/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:443:in `block in load_file'
from /home/sahil/.rvm/gems/[email protected]/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:633:in `new_constants_in'
from /home/sahil/.rvm/gems/[email protected]/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:442:in `load_file'
from /home/sahil/.rvm/gems/[email protected]/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:342:in `require_or_load'
from /home/sahil/.rvm/gems/[email protected]/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:480:in `load_missing_constant'
from /home/sahil/.rvm/gems/[email protected]/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:180:in `const_missing'
from (irb):16
from /home/sahil/.rvm/gems/[email protected]/gems/railties-4.1.1/lib/rails/commands/console.rb:90:in `start'
from /home/sahil/.rvm/gems/[email protected]/gems/railties-4.1.1/lib/rails/commands/console.rb:9:in `start'
from /home/sahil/.rvm/gems/[email protected]/gems/railties-4.1.1/lib/rails/commands/commands_tasks.rb:69:in `console'
from /home/sahil/.rvm/gems/[email protected]/gems/railties-4.1.1/lib/rails/commands/commands_tasks.rb:40:in `run_command!'
from /home/sahil/.rvm/gems/[email protected]/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/[email protected]/gems/activerecord-4.1.1/lib/active_record/dynamic_matchers.rb:26:in `method_missing'
from /home/sahil/.rvm/gems/[email protected]/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>'
請告訴我發生了什麼錯在這裏。我是否缺少一些所需的依賴關係?