From 01d6c0e97df047432ed51e549605776567daefbd Mon Sep 17 00:00:00 2001 From: Andrew Tomaka Date: Mon, 27 Oct 2014 12:43:24 -0400 Subject: [PATCH] More verbose notices --- app/controllers/friendships_controller.rb | 4 ++-- app/models/friendship.rb | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) 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