开发者

wrong # of arguments(0 for 1)

Here is my Test model code:

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

This is the stacktrace I get when I run the following:

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

Check out the following:

>> 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/gem开发者_JAVA技巧s/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
>>

I get the feeling there is an issue with primary key definition in my model but i can't figure it out.


I suspect that naming your model Test is a source of trouble here. Open up the console and type Test. If it's actually finding your model you'll see something like this.

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

Although, my guess is that you're going to see this instead:

=> Test

Change your throw-away model to something like Foo and see how that goes.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜