我目前正在通过以下方式获取模型中的所有注释
@notes_list = current_user.notes.order(:title).group_by { |note| note.title[0] }
后来我在注释表中添加了一列,该列已知是 boolean 列。
现在我只想分别获取真值列和假值列,如下所示
@notes_true_list = blah....
@notes_false_list = blah....
有人可以帮助我吗?
最佳答案
尝试下面的代码。
@notes_true_list = current_user.notes.where(known: true).order(:title).group_by { |note| note.title[0] }
@notes_false_list = current_user.notes.where(known: false).order(:title).group_by { |note| note.title[0] }
关于ruby-on-rails - Rails 仅获取模型实例变量中的 true boolean 对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31228244/