Skip to content

Instantly share code, notes, and snippets.

@colmtuite
Created February 14, 2013 19:19
Show Gist options
  • Save colmtuite/4955490 to your computer and use it in GitHub Desktop.
Save colmtuite/4955490 to your computer and use it in GitHub Desktop.
user.rb
def unfollow!(other_user)
friendships.find_by_followed_id(other_user.id).destroy
end
users/show.html.erb
<% unless @user == current_user %>
<% if current_user.friends_with?(@user) %>
<%= form_for current_user.friendships.find_by_followed_id(@user),
html: { method: :delete } do |f| %>
<%= f.submit "Unfollow" %>
<% end %>
<% else %>
<%= link_to "Follow", friendships_path(:friend_id => @user), :method => :post, class: "btn-sml btn-accent" %>
<% end %>
<% end %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment