ruby - nil:NilClass Ruby 的未定义方法“<=”
问题描述
我有一个 Ruby 模型Book.rb
,它具有以下内容:
class Book < Library
field :name
field :checked_out, default: false
field :checked_in, default: true
def checked_out?
checked_out && !checked_in
end
def checked_in?
checked_in && !checked_out
end
然后,在我的index.haml
文件中,有以下内容:
-@books.each do |book|
haml :"books/list_all" locals: {book: book}
最后,在我的list_all.haml
文件中,我有:
.h4
#{book.name}
- if "#{book.checked_in?}"
Book is checked in
- else
Book is checked out
更新:book_routes.rb
get '/' do
haml :'books/index'
end
但是,我得到一个 undefined method <= for nil:NilClass
错误。我怎样才能解决这个问题?
解决方案
推荐阅读
- r - 使用包“cmprsk”在 R 中自定义竞争风险图
- angular - RxJS 操作员在后台使用 .subscribe() 吗?
- flutter - 如何通过单击 Flutter 页面中存在的按钮导航到 BottomNavigationBar 的页面之一?
- python - 为列表中的每个条目创建标签,但最后一个条目没有创建标签
- docker - 带有 terraform 和 efs 的 AWS ECS 任务定义 - 未知卷
- android - Android 11 MediaStyle 通知崩溃
- java - 这会给我正确的用户当地时间吗?
- javascript - JavaScript 中的任务
- java - 如何扫描这一行并使用 scan.skip()?
- git - 如何更新本地 git 存储库以有效反映已删除的子模块?