Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Friendship < ApplicationRecord
- belongs_to :user
- belongs_to :friend, :class_name => "User"
- end
- def search
- @users = User.search(params[:search_param]) #this .search is a class level method, which is defined in the user.rb file
- if @users
- @users = current_user.except_current_user(@users)
- render partial: "friends/lookup"
- else
- render status: :not_found, nothing: true
- end
- end
- <div id="friend-lookup">
- <h3>Search for friends</h3>
- <%= form_tag search_friends_path, remote: true, method: :get, id: "friend-lookup-form" do %>
- <div class="form-group row no-padding text-center col-md-12">
- <div class="col-md-10">
- <%= text_field_tag :search_param, params[:search_param], placeholder: "First name, last name or email", autofocus: true, class: "form-control search-box
- input-lg" %>
- </div>
- <div class="col-md-2">
- <%= button_tag(type: :submit, class: "btn btn-lg btn-success") do %>
- <i class="fa fa-search"></i> Look up a friend
- <% end %>
- </div>
- </div>
- <% end %>
- <%= render 'common/spinner' %>
- <% if @users %>
- <% if @users.size > 0 %>
- <div id="friend-lookup-results" class="well results-block">
- <table class="search-results-table col-md-12">
- <tbody>
- <% @users.each do |user| %>
- <tr>
- <td><strong>Name</strong><%= @user.full_name %></td>
- <td><strong>Email</strong><%= @user.email %></td>
- <td><strong>Placeholder</strong><%= @user.full_name %></td> <!-- transaction -->
- <td><% if current_user.not_friends_with?(user.id) %>
- <%= link_to "Add as friend", add_friend_path(user: current_user, friend: user),
- class: "btn btn-xs btn-success", method: :post %>
- <% else %>
- <span class = "label label-primary">
- You are friends
- </span>
- <% end %>
- </td>
- </tr>
- <% end %>
- </tbody>
- </table>
- </div>
Add Comment
Please, Sign In to add comment