2015-03-25 73 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) 
相关问题