2.dynamic find by methods

简介:
先来看这段代码:

incomplete方法用来查询所有未完成的任务, conditions这个option后面的参数是一个数组,'complete = ?' ?是一个占位符,false是它的实际值,这个语句等价于:
@tasks = Task.find(:all, :conditions=>"complete = false")

----
这个方法也可以用find_by_... 方法来写,可读性更强:





本文转自 fsjoy1983 51CTO博客,原文链接:http://blog.51cto.com/fsjoy/97098,如需转载请自行联系原作者
目录
相关文章
|
6月前
Each child in a list should have a unique “key“ prop. Check the render method的报错解决
Each child in a list should have a unique “key“ prop. Check the render method的报错解决
【已解决】Error: Element type is invalid: expected a string (for built-in components) or a class/function
Error: Element type is invalid: expected a string (for built-in components) or a class/function
2570 0
【已解决】Error: Element type is invalid: expected a string (for built-in components) or a class/function
Unknown custom element: <add-employee> - did you register the component correctly? For red cursive c
原因: 1.组件名没写对(导入和注册不对应) 2.components少写了个s 3.组件命名最好是驼峰命名 4.导入时语法错误 5.代码中有两个components,后一个的值把前一个覆盖了 6.组件直接循环套用了
104 0
|
7月前
|
JavaScript
[Vue warn]_ Avoid using non-primitive value as key, use string_number value instea
[Vue warn]_ Avoid using non-primitive value as key, use string_number value instea
85 1
|
7月前
|
JavaScript
[Vue warn]: Method “components“ has type “object“ in the component definition. Did you reference the
[Vue warn]: Method “components“ has type “object“ in the component definition. Did you reference the
|
编解码 搜索推荐 算法
Data-Data Objects and Attribute Types| 学习笔记
快速学习 Data-Data Objects and Attribute Types。
Data-Data Objects and Attribute Types| 学习笔记
|
XML Java 数据库连接
Open quote is expected for attribute "{1}" associated with an element type "id".
Open quote is expected for attribute "{1}" associated with an element type "id".
209 0
Open quote is expected for attribute "{1}" associated with an element type "id".
成功解决AttributeError: 'MapDataset' object has no attribute 'group_by_window'
成功解决AttributeError: 'MapDataset' object has no attribute 'group_by_window'
成功解决AttributeError: 'MapDataset' object has no attribute 'group_by_window'