неверное количество аргументов (0 для 1) - PullRequest
1 голос
/ 24 августа 2010

Вот код моей тестовой модели:

require 'rubygems'
require 'composite_primary_keys'
class VamTest < ActiveRecord::Base
  set_table_name 'tests'
  set_primary_keys :service, :host
end

Это трассировка стека, которую я получаю, когда запускаю следующее:

>> VamTest.all
VamTest.all
ArgumentError: wrong # of arguments(0 for 1)
    from C:/jruby/jruby-1.5.1/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:1:in `class_eval'
    from C:/jruby/jruby-1.5.1/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:2232:in `compute_type'
    from C:/jruby/jruby-1.5.1/lib/ruby/gems/1.8/gems/activesupport-2.3.8/lib/active_support/core_ext/kernel/reporting.rb:11:in `silence_warnings'
    from C:/jruby/jruby-1.5.1/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:2230:in `compute_type'
    from C:/jruby/jruby-1.5.1/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:1665:in `instantiate'
    from C:/jruby/jruby-1.5.1/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:664:in `find_by_sql'
    from C:/jruby/jruby-1.5.1/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:664:in `collect!'
    from C:/jruby/jruby-1.5.1/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:664:in `find_by_sql'
    from C:/jruby/jruby-1.5.1/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:1578:in `find_every'
    from C:/jruby/jruby-1.5.1/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:618:in `find'
    from C:/jruby/jruby-1.5.1/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:638:in `all'
    from (irb):2
>> 

Проверьте следующее:

>> VamTest.find(:first)
VamTest.find(:first)
ArgumentError: wrong # of arguments(0 for 2)
    from C:/jruby/jruby-1.5.1/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:1:in `class_eval'
    from C:/jruby/jruby-1.5.1/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:2232:in `compute_type'
    from C:/jruby/jruby-1.5.1/lib/ruby/gems/1.8/gems/activesupport-2.3.8/lib/active_support/core_ext/kernel/reporting.rb:11:in `silence_warnings'
    from C:/jruby/jruby-1.5.1/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:2230:in `compute_type'
    from C:/jruby/jruby-1.5.1/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:1665:in `instantiate'
    from C:/jruby/jruby-1.5.1/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:664:in `find_by_sql'
    from C:/jruby/jruby-1.5.1/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:664:in `collect!'
    from C:/jruby/jruby-1.5.1/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:664:in `find_by_sql'
    from C:/jruby/jruby-1.5.1/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:1578:in `find_every'
    from C:/jruby/jruby-1.5.1/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:1535:in `find_initial'
    from C:/jruby/jruby-1.5.1/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:616:in `find'
    from (irb):31
>>

У меня такое ощущение, что в моей модели есть проблема с определением первичного ключа, но я не могу понять это.

1 Ответ

0 голосов
/ 24 августа 2010

Я подозреваю, что название вашей модели Test является источником проблем здесь.Откройте консоль и введите Test.Если он действительно находит вашу модель, вы увидите что-то вроде этого.

=> Testid: integer, service: string, host: string, created_at: datetime, updated_at: datetime

Хотя, я думаю, вы увидите это вместо этого:

=> Test

Измените свою одноразовую модель на что-то вроде Foo и посмотрите, как это получится.

...