0
我工作的Rails应用程序在那里我有一个可以加对方为好友的用户匹配。 现在我想显示在用户已经是另一个用户的好友的某些信息。我以下列方式完成了这项工作:查找阵列
- @users.each do |user|
- exists = false
- current_user.friends.each do |friend|
- if friend == user
- exists = true
- if !exists
= button_to 'Add Friend', friendships_path(:friend_id => user), :method => :post
- else
Already a friend
我觉得这个解决方案不好。你知道我怎样才能以干净和高效的方式做到这一点?
谢谢!很棒。一个小的评论;应该切换if/else内容。 – 2010-11-13 12:23:58
更简单:'current_user.friends.include? user' – 2010-11-13 14:41:35