Disqus 无法加载。如果您是管理员,请参阅故障排除指南

Tim Chang • 6 年之前

看起來是 find 只能找id
find_by 可以找 裡面所有的元素 (title, description, quantity, price)

刘华佼 • 6 年之前

Dash上找到的:
find的用法:
Person.find(1) # returns the object for ID = 1
Person.find("1") # returns the object for ID = 1
Person.find("31-sarah") # returns the object for ID = 31
Person.find(1, 2, 6) # returns an array for objects with IDs in (1, 2, 6)
Person.find([7, 17]) # returns an array for objects with IDs in (7, 17)
Person.find([1]) # returns an array for the object with ID = 1
Person.where("administrator = 1").order("created_on DESC").find(1)

find_by的用法:
Post.find_by name: 'Spartacus', rating: 4
Post.find_by "published_at < ?", 2.weeks.ago

看起来你说的是对的,Person.find("31-sarah"),rating: 4,2.weeks.ago 就是这些不太明白,但不是高频小套路就不用care了。

刘华佼 • 6 年之前

附上Nic老师的回答:

1)
31-sarah,这是找某笔数据吧,不代表任何意义
rating: 4 ,只是他想要找这个 table 里面的 rating 栏位,数值是4而已
2.weeks.ago,直接翻中文就知道意思了,这个是 ruby 的用法,可以查询 ruby week ago 搜看看 google