Skip to content

Instantly share code, notes, and snippets.

@liwh
Created September 8, 2010 03:49
Show Gist options
  • Save liwh/569586 to your computer and use it in GitHub Desktop.
Save liwh/569586 to your computer and use it in GitHub Desktop.
>> New.find(1)
ActiveRecord::RecordNotFound: Couldn't find New with ID=1
from /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/base.rb:1591:in `find_one'
from /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/base.rb:1574:in `find_from_ids'
from /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/base.rb:616:in `find'
from (irb):4
>> New.find_by_id(1)
=> nil
//直接利用find方式查找,如果没有数据会跑出异常,而利用find_by_id方式会返回nil
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment