Rails - check if record exists in has_many association

后端 未结 4 1875
滥情空心
滥情空心 2021-01-01 13:33

I\'m not sure if my question is worded correctly.

I have three models: User, Item, and UserItem.

user has_many         


        
4条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-01 14:07

    Try:

    current_user.items.exists?(params[:id])
    

    Or

    current_user.items.exists?(@item.id)
    

提交回复
热议问题