Rails5:将 find(:all, condition...) 转换为 "where"



(我已经厌倦了问这些如何将x转换成y的问题)

我如何转换这个废弃的rails 2行

Program.find(:all, :conditions => {:volunteer => true})]

变成"where"Rails 5的语句?

Program.find(:all, where(:volunteer => true))]

还有,有没有一个来源有很多很多转换"条件"的例子?";where" ?

如果志愿者是你想要的栏目

Program.where(volunteer: true)

不需要查找。活动记录文档是一个很好的参考https://guides.rubyonrails.org/active_record_querying.html

我只写过rails 5/6但是我用

Model.find(id) # find exactly one
Model.find_by(column: value, column2: val2) # find exactly one by other cols
Model.where(col: val) # find 0 to many models by columns value