我正在尝试根据“用户”是否为“成员(member)”来构建条件。基本上我需要一种方法来检查 current_user.id 是否与任何成员的任何 user_id 匹配。我现在的非工作代码是:
<% if current_user = @page.members %>
you can view this content.
<% end %>
我正在寻找类似以下内容的内容:“如果 current_user.id 存在于任何成员的“user_id”中。”
最佳答案
类似这样的内容,基于您问题中的字段名称:
<% if @page.members.map(&:user_id).include? current_user.id %>
You can view this content
<% end %>
关于ruby-on-rails - Rails 检查用户 ID 是否在数组中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10289836/