diff --git a/app/controllers/friendships_controller.rb b/app/controllers/friendships_controller.rb index 7aa233e..71371b3 100644 --- a/app/controllers/friendships_controller.rb +++ b/app/controllers/friendships_controller.rb @@ -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 diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index bbab75d..2eae0c1 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -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 diff --git a/app/models/friendship.rb b/app/models/friendship.rb index 7d81232..bc7f6aa 100644 --- a/app/models/friendship.rb +++ b/app/models/friendship.rb @@ -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 diff --git a/app/views/friendships/index.html.erb b/app/views/friendships/index.html.erb index de0c92f..c4db4ac 100644 --- a/app/views/friendships/index.html.erb +++ b/app/views/friendships/index.html.erb @@ -1,4 +1,4 @@ -

Listing friendships

+

Friends List

@@ -13,7 +13,7 @@ <% @friendships.each do |friendship| %> - +
<%= friendship.friend.name %><%= link_to friendship.friend.name, friendship.friend %> <%= friendship.created_at %> <%= friendship.updated_at %> [ <%= link_to 'Destroy', friendship, method: :delete, diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb index 301bd6e..61ddb30 100644 --- a/app/views/users/show.html.erb +++ b/app/views/users/show.html.erb @@ -1,2 +1,4 @@ -

User#show

-

Find me in app/views/user/show.html.erb

+

<%= @user.name %>

+Friends: <%= @user.friends.count %>
+Created: <%= @user.created_at %>
+Updarted: <%= @user.updated_at %>