Rails Console find users by array of ids

前端 未结 6 1485
清歌不尽
清歌不尽 2020-12-23 19:25

So I have an array of user ids. Is there a way in rails console to query all of these user\'s with the array

something like

ids = [1, 2, 3, 4]

users         


        
6条回答
  •  心在旅途
    2020-12-23 19:43

    Use splash operator:

    ids = [1, 2, 3, 4]
    
    users = User.find(*ids)
    

    Note that it will raise an exception if it fails to find any of the users.

提交回复
热议问题