2013-05-14 43 views

回答

2

什么如果,例如,你的模型是用户,找到您要使用的所有用户:

User.all 

和特定的条件下,你可以使用:

​​
2

您可以使用where

Foo.where(:stuff => stuff, :thing => thing) 
# or 
Foo.where("stuff = ? AND thing = ?", stuff, thing) 

另见Rails .where vs .find ...

要查找所有(再次作为ActiveRecord::Relation对象,而不是一个数组),你可以使用scoped

Foo.scoped 
+0

不串起到什么功能? – Btuman 2013-05-14 18:01:13

+0

@Btuman它是与SQL注入作斗争(在[docs](http://guides.rubyonrails.org/active_record_querying.html#conditions)中推荐)。 – 2013-05-14 18:03:07

+0

我想.where()是将条件=> {}转换为当前的格式,我错过了什么吗? – Btuman 2013-05-14 18:06:10