Guest User

Untitled

a guest
Oct 21st, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.01 KB | None | 0 0
  1. class Friendship < ApplicationRecord
  2. belongs_to :user
  3. belongs_to :friend, :class_name => "User"
  4. end
  5.  
  6. def search
  7. @users = User.search(params[:search_param]) #this .search is a class level method, which is defined in the user.rb file
  8.  
  9. if @users
  10. @users = current_user.except_current_user(@users)
  11.  
  12. render partial: "friends/lookup"
  13. else
  14. render status: :not_found, nothing: true
  15. end
  16.  
  17. end
  18.  
  19. <div id="friend-lookup">
  20. <h3>Search for friends</h3>
  21. <%= form_tag search_friends_path, remote: true, method: :get, id: "friend-lookup-form" do %>
  22. <div class="form-group row no-padding text-center col-md-12">
  23. <div class="col-md-10">
  24. <%= text_field_tag :search_param, params[:search_param], placeholder: "First name, last name or email", autofocus: true, class: "form-control search-box
  25. input-lg" %>
  26. </div>
  27. <div class="col-md-2">
  28. <%= button_tag(type: :submit, class: "btn btn-lg btn-success") do %>
  29. <i class="fa fa-search"></i> Look up a friend
  30. <% end %>
  31. </div>
  32. </div>
  33. <% end %>
  34.  
  35. <%= render 'common/spinner' %>
  36.  
  37. <% if @users %>
  38. <% if @users.size > 0 %>
  39. <div id="friend-lookup-results" class="well results-block">
  40. <table class="search-results-table col-md-12">
  41. <tbody>
  42. <% @users.each do |user| %>
  43. <tr>
  44. <td><strong>Name</strong><%= @user.full_name %></td>
  45. <td><strong>Email</strong><%= @user.email %></td>
  46. <td><strong>Placeholder</strong><%= @user.full_name %></td> <!-- transaction -->
  47. <td><% if current_user.not_friends_with?(user.id) %>
  48. <%= link_to "Add as friend", add_friend_path(user: current_user, friend: user),
  49. class: "btn btn-xs btn-success", method: :post %>
  50. <% else %>
  51. <span class = "label label-primary">
  52. You are friends
  53. </span>
  54. <% end %>
  55. </td>
  56. </tr>
  57. <% end %>
  58. </tbody>
  59. </table>
  60. </div>
Add Comment
Please, Sign In to add comment