我經歷邁克爾·哈特爾的Rails的教程,特別是第6章:邁克爾·哈特爾的Rails的教程:User.find(1)銷燬方法之後顯示堆棧跟蹤
http://ruby.railstutorial.org/chapters/modeling-and-viewing-users-one#sec:finding_user_objects
後,我做了User.find (1)user.destroy命令後,我得到了以下錯誤消息:
ruby-1.9.2-p290 :006 > User.find(1)
ActiveRecord::RecordNotFound: Couldn't find User with ID=1
from /Users/me/.rvm/gems/[email protected]/gems/activerecord-3.0.9/lib/active_record/relation/finder_methods.rb:304:in `find_one'
from /Users/me/.rvm/gems/[email protected]/gems/activerecord-3.0.9/lib/active_record/relation/finder_methods.rb:289:in `find_with_ids'
from /Users/me/.rvm/gems/[email protected]/gems/activerecord-3.0.9/lib/active_record/relation/finder_methods.rb:107:in `find'
from /Users/me/.rvm/gems/[email protected]/gems/activerecord-3.0.9/lib/active_record/base.rb:444:in `find'
from (irb):6
from /Users/me/.rvm/gems/[email protected]/gems/railties-3.0.9/lib/rails/commands/console.rb:44:in `start'
from /Users/me/.rvm/gems/[email protected]/gems/railties-3.0.9/lib/rails/commands/console.rb:8:in `start'
from /Users/me/.rvm/gems/[email protected]/gems/railties-3.0.9/lib/rails/commands.rb:23:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
我一般是新的節目,我不知道從哪裏着手。用谷歌搜索錯誤信息沒有任何用處。一切看起來都很好,我只是不知道爲什麼我會在例外情況下得到錯誤信息。
啊好吧,我假設堆棧跟蹤的是「預期的行爲?」 – dartfrog
是,正好:) – mkk
或'find_by_id',它是上面的一個較短版本。 –