Ruby on rails 4 创建共同好友列表
我已经阅读了关于Treehouse的Treebook教程,我一直在努力增强它 我想在profile_页面上添加一个共同好友列表,显示您与该用户的共同好友 我可以编写一个if语句来显示普通用户的profile_名称 例如Ruby on rails 4 创建共同好友列表,ruby-on-rails-4,Ruby On Rails 4,我已经阅读了关于Treehouse的Treebook教程,我一直在努力增强它 我想在profile_页面上添加一个共同好友列表,显示您与该用户的共同好友 我可以编写一个if语句来显示普通用户的profile_名称 例如 但我想写一个块来浏览并显示其他信息。如何在配置文件控制器中创建查询,以便在块中使用它?因此您需要类似以下内容: def common_friends Friends.where(friends: [friend1, friend2]) end 通过这种方式,您可以查询
但我想写一个块来浏览并显示其他信息。如何在配置文件控制器中创建查询,以便在块中使用它?因此您需要类似以下内容:
def common_friends
Friends.where(friends: [friend1, friend2])
end
通过这种方式,您可以查询朋友列表中同时包含friend1和friend2的朋友。在其他地方收到了一些帮助。我对过度思考这个问题感到内疚
@common_friends = current_user.friends & @user.friends
然后使用:
<% @common_friends.each do |friend|%>
<%= friend.profile_name %>
<% end %>
<% @common_friends.each do |friend|%>
<%= friend.profile_name %>
<% end %>