首页 > 解决方案 > 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错误。我怎样才能解决这个问题?

标签: rubysinatrahaml

解决方案


推荐阅读