我是Rails的新手,但我需要在运行Ruby 1.9.2和Rails 3的应用程序中使用复合主键。我无法在Ruby on Rails应用程序中使复合键正常工作。我按照the compositekeys site中的说明进行操作,但我仍然遇到同样的错误: 没有要加载的文件 - composite_primary_keys
1 - sudo gem install composite_primary_keys
2 - 在conf / environment.rb文件的末尾添加require'composite_primary_keys'
3 - 添加了set_primary_keys
我的宝石列表如下所示:
abstract (1.0.0)
actionmailer (3.0.1)
actionpack (3.0.1)
activemodel (3.0.3, 3.0.1)
activerecord (3.0.1)
activeresource (3.0.1)
activesupport (3.0.3, 3.0.1)
arel (2.0.3, 1.0.1)
builder (2.1.2)
bundler (1.0.3)
composite_primary_keys (2.3.5.1)
我的域类看起来像这样:
class Radioreport < ActiveRecord::Base
set_primary_keys :service_id, :date_id
belongs_to :report_date, :foreign_key => "date_id"
belongs_to :service, :foreign_key => "service_id"
...
我的环境文件如下所示:
# Load the rails application
require File.expand_path('../application', __FILE__)
# Initialize the rails application
Upreports::Application.initialize!
require 'composite_primary_keys'
当我运行'rake test'时,我得到的错误如下:
rake aborted!
no such file to load -- composite_primary_keys
单元测试是:
require 'test_helper'
require 'rubygems'
require 'composite_primary_keys'
class RadioreportTest < ActiveSupport::TestCase
fixtures :radioreports, :services, :genres, :groups, :locations, :report_dates
def setup
@radioReport = Radioreport.new
end
def test_should_put_all_radios_and_totals_in_a_hash
transactions = Radioreport.find(:all)
reportTransactions = @radioReport.getRadioTotalsByDayMap(transactions)
assert_not_nil(reportTransactions)
assert_equal(2, reportTransactions.size)
previousKey = nil
previousValue = nil
reportTransactions.each{|key, value|
if(previousKey == nil || previousValue == nil)
previousKey = key
previousValue = value
else
assert_not_nil(key)
assert_not_equal(previousKey, key)
assert_not_nil(value)
assert_not_equal(previousValue, value)
end
}
end
我检查了以下thread,但这个不适用。我已经检查了我的耙子,宝石等 多谢你们! ;)