You can pass an array as an attribute value for the where method:
all_projects = [1, 2, 5, 8, 16] url_lists = UrlList.where(:project_id => all_projects)
It will generate an SQL query as follows:
SELECT `url_lists`.* FROM `url_lists` WHERE `project_id`.`user_id` IN (1, 2, 5, 8, 16)
source share