rails控制器索引渲染验证

时间:2016-12-25 22:46:19

标签: ruby-on-rails

如何让它发挥作用?

books_controller.rb:

1)

def index
  @books = Book.where(library_id.present?)
end

2)

def warsaw_books
  @books = Book.where(city == 'Warsaw')
end

1 个答案:

答案 0 :(得分:0)

1)查找library_id不为零的记录:

def index
  @books = Book.where.not(library_id: nil)
end

2)查找city'Warsaw'的记录:

def warsaw_books
  @books = Book.where(city: 'Warsaw')
end