1
0
Fork 0

Can only add a friend one time

This commit is contained in:
Andrew Tomaka 2014-10-27 12:25:36 -04:00
parent 461d3c6b7b
commit 1919d618aa
5 changed files with 17 additions and 6 deletions

View file

@ -10,10 +10,10 @@ class FriendshipsController < ApplicationController
if @friendship.save
flash[:notice] = 'Added friend.'
redirect_to root_url
redirect_to friendships_path
else
flash[:notice] = 'Unable to add friend.'
redirect_to root_url
redirect_to users_path
end
end

View file

@ -4,5 +4,12 @@ class UsersController < ApplicationController
end
def show
@user = User.find(params[:id])
end
private
def user_params
params.permit(:id)
end
end

View file

@ -1,4 +1,6 @@
class Friendship < ActiveRecord::Base
belongs_to :user
belongs_to :friend, class_name: 'User'
validates_uniqueness_of :friend_id, :scope => :user_id
end

View file

@ -1,4 +1,4 @@
<h2>Listing friendships</h2>
<h2>Friends List</h2>
<table class="table table-striped table-hover">
<thead>
@ -13,7 +13,7 @@
<tbody>
<% @friendships.each do |friendship| %>
<tr>
<td><%= friendship.friend.name %></td>
<td><%= link_to friendship.friend.name, friendship.friend %></td>
<td><%= friendship.created_at %></td>
<td><%= friendship.updated_at %></td>
<td>[ <%= link_to 'Destroy', friendship, method: :delete,

View file

@ -1,2 +1,4 @@
<h1>User#show</h1>
<p>Find me in app/views/user/show.html.erb</p>
<h2><%= @user.name %></h2>
Friends: <%= @user.friends.count %><br/>
Created: <%= @user.created_at %><br/>
Updarted: <%= @user.updated_at %><br/>