find_by_user_id_and_activity_id 只显示一条记录

find_by_user_id_and_activity_id displaying only one record

我有一个 table 用户

但它只给出了一条记录。

如何获取所有值?

你没有给出太多的继续,但如果使用 Rails 4,也许你可以尝试 return 一条记录:

User.find_by(user_id: 5, activity_id: 11)

User.where(user_id: 5, activity_id: 11) to return a collection.

请使用以下查询获取具有特定 user_id 和 activity_id 的所有记录。

User.where(user_id: 5, activity_id: 11)

它给你一个 ActiveRecord::Relation 的数组。

As per documaention of find_by(args)
Finds the first record matching the specified conditions.
Reference: http://api.rubyonrails.org/classes/ActiveRecord/FinderMethods.html