我是rails開發新手,並且一直在使用rails控制檯來適應它。當我嘗試通過.find_by_id()
查找記錄時,它會拋出一個缺少錯誤的方法。Rails 4 - .find_by_id()給方法缺少錯誤?
看起來好像有活動記錄寶石出了問題,但我跑gem update
更新了活動記錄寶石,我仍然得到相同的錯誤...我不確定問題究竟是什麼。
幫助非常感謝!
NoMethodError: undefined method `find_by_id' for #<Class:0x007fdd03515238>
from /usr/local/lib/ruby/gems/2.2.0/gems/activerecord-4.2.3/lib/active_record/dynamic_matchers.rb:26:in `method_missing'
from (irb):1
您調用'.find_by_id'的類是否繼承自'ActiveRecord :: Base'? – jasonmklug
它應該是一個內置的rails方法,如'find()'..我將如何檢查它的繼承? – Gcap
查找相關類的文件(可能在'app/models/your_class.rb'中),並確保'class YourClass
jasonmklug