开发者

Ruby error no such file to load -- composite_primary_keys

I'm new to Rails but I need to use a composite primary key in my app running Ruby 1.9.2 and Rails 3. I am not able to get composite keys working properly in my Ruby on Rails app. I've followed the directions in the compositekeys site but I'm still getting the same error: no such file to load -- composite_primary_keys

1 - sudo gem install composite_primary_keys

2 - Add the require 'composite_primary_keys' at the end of the conf/environment.rb file

3 - Added the set_primary_keys

My gem list looks like this:

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)

My domain class looks like this:

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"
  ...

And my environment file looks like this:

 # Load the rails application
 require File.expand_path('../application', __FILE__)
 # Initialize the rails application
 Upreports::Application.initialize!
 require 'composite_primary_keys'

The error that I get is the following when I run my 'rake test':

rake aborted!
no such file to load -- composite_primary_keys

The unit test is:

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开发者_如何学Go_not_equal(previousKey, key)
        assert_not_nil(value)
        assert_not_equal(previousValue, value)
      end
    }
  end

I checked the following thread, but this one doesn't apply. I already checked my rake, gem, etc.

Thanks guys! ;)


According to the discussion in Github, CPK doesn't yet support Rails 3. However, there seem to be people working in various forks to get this to work.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜