活动记录未定义方法`eq'

时间:2011-03-27 09:27:26

标签: ruby-on-rails activerecord

我的桌面锦标赛有字段user_id,question_id,answer和我创建的关键字

Primary key (user_id, question_id)

但是当我想改变这样的答案字段时:

t=Tournament.where('question_id=200').first
t.answer=2
t.save

我有错误:

NoMethodError: undefined method `eq' for nil:NilClass
    from /home/marat/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.0.4/lib/active_support/whiny_nil.rb:48:in `method_missing'
    from /home/marat/.rvm/gems/ruby-1.9.2-p0/gems/activerecord-3.0.4/lib/active_record/persistence.rb:255:in `update'
    from /home/marat/.rvm/gems/ruby-1.9.2-p0/gems/activerecord-3.0.4/lib/active_record/locking/optimistic.rb:77:in `update'
    from /home/marat/.rvm/gems/ruby-1.9.2-p0/gems/activerecord-3.0.4/lib/active_record/attribute_methods/dirty.rb:68:in `update'
    from /home/marat/.rvm/gems/ruby-1.9.2-p0/gems/activerecord-3.0.4/lib/active_record/timestamp.rb:60:in `update'
    from /home/marat/.rvm/gems/ruby-1.9.2-p0/gems/activerecord-3.0.4/lib/active_record/callbacks.rb:285:in `block in update'
    from /home/marat/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.0.4/lib/active_support/callbacks.rb:413:in `_run_update_callbacks'
    from /home/marat/.rvm/gems/ruby-1.9.2-p0/gems/activerecord-3.0.4/lib/active_record/callbacks.rb:285:in `update'
    from /home/marat/.rvm/gems/ruby-1.9.2-p0/gems/activerecord-3.0.4/lib/active_record/persistence.rb:246:in `create_or_update'
    from /home/marat/.rvm/gems/ruby-1.9.2-p0/gems/activerecord-3.0.4/lib/active_record/callbacks.rb:277:in `block in create_or_update'
    from /home/marat/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.0.4/lib/active_support/callbacks.rb:423:in `_run_save_callbacks'
    from /home/marat/.rvm/gems/ruby-1.9.2-p0/gems/activerecord-3.0.4/lib/active_record/callbacks.rb:277:in `create_or_update'
    from /home/marat/.rvm/gems/ruby-1.9.2-p0/gems/activerecord-3.0.4/lib/active_record/persistence.rb:56:in `save!'
    from /home/marat/.rvm/gems/ruby-1.9.2-p0/gems/activerecord-3.0.4/lib/active_record/validations.rb:49:in `save!'
    from /home/marat/.rvm/gems/ruby-1.9.2-p0/gems/activerecord-3.0.4/lib/active_record/attribute_methods/dirty.rb:30:in `save!'
    from /home/marat/.rvm/gems/ruby-1.9.2-p0/gems/activerecord-3.0.4/lib/active_record/transactions.rb:245:in `block in save!'
    from /home/marat/.rvm/gems/ruby-1.9.2-p0/gems/activerecord-3.0.4/lib/active_record/transactions.rb:292:in `block in with_transaction_returning_status'
    from /home/marat/.rvm/gems/ruby-1.9.2-p0/gems/activerecord-3.0.4/lib/active_record/connection_adapters/abstract/database_statements.rb:139:in `transaction'
    from /home/marat/.rvm/gems/ruby-1.9.2-p0/gems/activerecord-3.0.4/lib/active_record/transactions.rb:207:in `transaction'
    from /home/marat/.rvm/gems/ruby-1.9.2-p0/gems/activerecord-3.0.4/lib/active_record/transactions.rb:290:in `with_transaction_returning_status'
    from /home/marat/.rvm/gems/ruby-1.9.2-p0/gems/activerecord-3.0.4/lib/active_record/transactions.rb:245:in `save!'
    from (irb):4
    from /home/marat/.rvm/gems/ruby-1.9.2-p0/gems/railties-3.0.4/lib/rails/commands/console.rb:44:in `start'
    from /home/marat/.rvm/gems/ruby-1.9.2-p0/gems/railties-3.0.4/lib/rails/commands/console.rb:8:in `start'
    from /home/marat/.rvm/gems/ruby-1.9.2-p0/gems/railties-3.0.4/lib/rails/commands.rb:23:in `<top (required)>'
    from script/rails:6:in `require'

任何人都可以帮助我吗? 感谢。

1 个答案:

答案 0 :(得分:0)

您是否根据标准的Rails创建了表格?

如果是,请参阅undefined method `eq' for nil:NilClass with rails 3 and ruby enterprise on ubuntu hardy