簡體   English   中英

nil的未定義方法`eq':帶有rails 3的NilClass和ubuntu hardy上的ruby enterprise

[英]undefined method `eq' for nil:NilClass with rails 3 and ruby enterprise on ubuntu hardy

我不確定是什么原因引起了這個錯誤但是因為我在乘客中遇到了這個問題而現在在控制台中我也在想,也許mysql驅動程序是問題所在? 在osx / 10.6上,一切都按預期工作。 它只是不會在Ubuntu 8.04上耐用。

我把問題釘在了“destroy”方法上,或者當我直接調用activerecord實例的方法時。 為什么會這樣? 有任何想法嗎?

系統:

  • Ubuntu 8.04耐用。
  • ruby 1.8.7(2010-04-19 patchlevel 253)[i686-linux],MBARI 0x8770,Ruby Enterprise Edition 2010.02
  • rails 3.0.0-beta4
  • mysql Ver 14.12 Distrib 5.0.51a,debian-linux-gnu(i486)使用readline 5.2

這是錯誤輸出

root@gehege:/var/www/foobar.com/api.foobar.com/v1# rake cleanup:status_cleanup RAILS_ENV=production --trace
(in /var/www/foobar.com/api.foobar.com/v1)
** Invoke cleanup:status_cleanup (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute cleanup:status_cleanup
rake aborted!
undefined method `eq' for nil:NilClass
/opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/activerecord-3.0.0.beta4/lib/active_record/persistence.rb:76:in `destroy'
/opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/activerecord-3.0.0.beta4/lib/active_record/locking/optimistic.rb:110:in `destroy'
/opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/activerecord-3.0.0.beta4/lib/active_record/callbacks.rb:278:in `destroy'
/opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/activesupport-3.0.0.beta4/lib/active_support/callbacks.rb:412:in `_run_destroy_callbacks'
/opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/activerecord-3.0.0.beta4/lib/active_record/callbacks.rb:278:in `destroy'
/opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/activerecord-3.0.0.beta4/lib/active_record/transactions.rb:230:in `destroy'
/opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/activerecord-3.0.0.beta4/lib/active_record/transactions.rb:287:in `with_transaction_returning_status'
/opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/activerecord-3.0.0.beta4/lib/active_record/connection_adapters/abstract/database_statements.rb:139:in `transaction'
/opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/activerecord-3.0.0.beta4/lib/active_record/transactions.rb:202:in `transaction'
/opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/activerecord-3.0.0.beta4/lib/active_record/transactions.rb:285:in `with_transaction_returning_status'
/opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/activerecord-3.0.0.beta4/lib/active_record/transactions.rb:230:in `destroy'
/var/www/foobar.com/api.foobar.com/v1/lib/tasks/cleanup.rake:8
/var/www/foobar.com/api.foobar.com/v1/lib/tasks/cleanup.rake:6:in `each'
/var/www/foobar.com/api.foobar.com/v1/lib/tasks/cleanup.rake:6
/opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:636:in `call'
/opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:636:in `execute'
/opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:631:in `each'
/opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:631:in `execute'
/opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:597:in `invoke_with_call_chain'
/opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/1.8/monitor.rb:242:in `synchronize'
/opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:590:in `invoke_with_call_chain'
/opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:583:in `invoke'
/opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2051:in `invoke_task'
/opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in `top_level'
/opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in `each'
/opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in `top_level'
/opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2068:in `standard_exception_handling'
/opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2023:in `top_level'
/opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2001:in `run'
/opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2068:in `standard_exception_handling'
/opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:1998:in `run'
/opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/rake-0.8.7/bin/rake:31
/opt/ree/bin/rake:19:in `load'
/opt/ree/bin/rake:19

編輯:

即使在運行apt-get更新/升級到最新的hardy軟件包並重新編譯ree和mysql gem之后我也會遇到同樣的錯誤。

回答我自己的問題:經過一些研究后我發現rails(activerecord)需要映射到模型的表上的id字段。 如果您使用鏈接表,則不需要它們 - 但對於您希望作為模型添加的表格,它們是。 在我的情況下,解決方案是添加

set_primary_key :cal_id

其中cal_id是我唯一的密鑰。

從沒有id字段的表中刪除時我有同樣的錯誤。 我認為這是一個Rails 3 beta 4錯誤。

在將沒有id的HABTM表轉換為has_many:through的連接模型后,我發現了這個問題。 我忘了添加:id列...

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM