Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Approve or Reject Followers using the Relationship Model from RailsTutorial.org
- private
- # Return an SQL condition for users followed by the given user.
- # We include the user's own id as well.
- def self.followed_by(user)
- following_ids = %(SELECT followed_id FROM relationships
- WHERE follower_id = :user_id AND status = "approved")
- where("user_id IN (#{following_ids}) OR user_id = :user_id",
- { :user_id => user })
- end
- <table summary="Information about following/followers">
- <tr>
- <td class="main">
- <% unless @users.empty? %>
- <ul class="users">
- <% @users.each do |user| %>
- <tr>
- <td><%= image_tag user.avatar.url(:thumb) %></td>
- <td><%= user.full_name %></td>
- <td><%= user.company %></td>
- <td><%= render 'decide_form' if signed_in? %></td>
- </tr>
- <% end %>
- </ul>
- <%= will_paginate @users %>
- <% end %>
- </td>
- </tr>
- </table>
- <div id="follow_form">
- <% if @user.following?(current_user) %>
- <%= render 'reject' %>
- <% else %>
- <tr><%= render 'accept' %></tr>
- <tr><%= render 'reject' %></tr>
- <% end %>
- <%= form_for current_user.relationships.find_by_followed_id(@user),
- :html => { :method => :delete } do |f| %>
- <div class="actions"><%= f.submit "Unfollow" %></div>
- <% end %>
Advertisement
Add Comment
Please, Sign In to add comment