diff --git a/app/controllers/friendships_controller.rb b/app/controllers/friendships_controller.rb index 71371b3..b3bc739 100644 --- a/app/controllers/friendships_controller.rb +++ b/app/controllers/friendships_controller.rb @@ -9,10 +9,10 @@ class FriendshipsController < ApplicationController @friendship = current_user.friendships.build(friendship_params) if @friendship.save - flash[:notice] = 'Added friend.' + flash[:success] = "#{@friendship.friend.name} added as friend" redirect_to friendships_path else - flash[:notice] = 'Unable to add friend.' + flash[:error] = "Unable to add friend: #{@friendship.error_messages}" redirect_to users_path end end diff --git a/app/models/friendship.rb b/app/models/friendship.rb index 0abf718..68cadc0 100644 --- a/app/models/friendship.rb +++ b/app/models/friendship.rb @@ -10,4 +10,8 @@ class Friendship < ActiveRecord::Base errors.add(:friend_id, 'cannot refer back to self') end end + + def error_messages + errors.full_messages.join(', ') + end end