0
我有自我指涉关联工作。我的问题是,在users/show上,我想根据用户与当前用户的关系显示不同的文本。Follow Model的条件链接
目前,如果用户=当前用户,我将它设置为不显示任何内容。如果用户不是当前用户,并且不是当前用户的朋友,我想显示一个链接以跟随用户。最后,如果用户不是当前用户,并且已经是当前用户的朋友,我想显示文本以说“朋友”。
friendship.rb
belongs_to :user
belongs_to :friend, :class_name => "User"
user.rb
has_many :friendships
has_many :friends, :through => :friendships
has_many :inverse_friendships, :class_name => "Friendship", :foreign_key => "friend_id"
has_many :inverse_friends, :through => :inverse_friendships, :source => :user
用户/显示
<% unless @user == current_user %>
<%= link_to "Follow", friendships_path(:friend_id => @user), :method => :post %>
<% end %>