Rails - Find By with 2 fields?

前端 未结 4 1200
再見小時候
再見小時候 2021-02-01 12:42

I have the following in a controller

def update
    @permission = Permission.find_by_user_id(params[:user_id])

But I want it to also find by a

4条回答
  •  迷失自我
    2021-02-01 13:05

    Rails 4 introduces the find_by method:

    Permission.find_by(user_id: params[:user_id], project_id: params[:project_id])
    

提交回复
热议问题