2015-03-25 74 views
0

我有三個表用戶,事件和EventInvitee。 用戶創建一個事件並在該事件中邀請其他用戶。 現在使用下面的代碼,我得到了在特定事件中受邀的所有用戶。如何檢查current_user是否存在於特定的記錄集中?

@event=Event.find(4) 
@event.event_invitees 

但現在我想檢查current_user存在於@ event.event_invitees中嗎?

我怎麼能這樣做?

EventInvitee表的字段是id,user_id,event_id和關係在這三個表中正確定義的。

請幫幫我。

在此先感謝。

回答

2

您可以檢查current_user是存在於選擇EventInvite的使用方法exists?

@event.event_invitees.exists?(user_id: current_user.id) 
相關問題