Rails: How to use scope to find an element in array of arrays

后端 未结 1 1785
Happy的楠姐
Happy的楠姐 2021-01-24 17:15

I have an array of arrays like [[\"2\",\"3\"], [\"3\",\"1\"], [\"6\", \"1\"]]. The first element of each sub-array is the user ID and the second one is the number o

相关标签:
1条回答
  • 2021-01-24 17:58
    class Event
      scope :mybooking, ->(user_ids) { where(user_id: user_ids) }
    end
    

    Now it is possible to do in controller:

    reservations = [["2","3"], ["3","1"], ["6", "1"]]
    Event.mybooking(reservations.map(&:first))
    
    0 讨论(0)
提交回复
热议问题