From e40843bccb64ef8d04d8f478e894385f70413b2e Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Fri, 16 May 2014 11:25:51 +1000 Subject: [PATCH] Allow error messages without attribute name. Improve enterprise relationship error message. --- Gemfile | 1 + Gemfile.lock | 7 +++++++ app/models/enterprise_relationship.rb | 2 +- 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index af4108c9eb..87566eebfa 100644 --- a/Gemfile +++ b/Gemfile @@ -35,6 +35,7 @@ gem 'geocoder' gem 'gmaps4rails' gem 'spinjs-rails' gem 'rack-ssl', :require => 'rack/ssl' +gem 'custom_error_message', :github => 'jeremydurham/custom-err-msg' gem 'foreigner' gem 'immigrant' diff --git a/Gemfile.lock b/Gemfile.lock index 87a0acf967..733ef43572 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -6,6 +6,12 @@ GIT actionpack (~> 3.0) activemodel (~> 3.0) +GIT + remote: git://github.com/jeremydurham/custom-err-msg.git + revision: 3a8ec9dddc7a5b0aab7c69a6060596de300c68f4 + specs: + custom_error_message (1.1.1) + GIT remote: git://github.com/openfoodfoundation/spree.git revision: da651b40f5c6cdd32e00b060729eb9aefd4f615f @@ -492,6 +498,7 @@ DEPENDENCIES coffee-rails (~> 3.2.1) comfortable_mexican_sofa compass-rails + custom_error_message! database_cleaner (= 0.7.1) db2fog debugger-linecache diff --git a/app/models/enterprise_relationship.rb b/app/models/enterprise_relationship.rb index 2afd8c8a3e..09fff8ba03 100644 --- a/app/models/enterprise_relationship.rb +++ b/app/models/enterprise_relationship.rb @@ -3,7 +3,7 @@ class EnterpriseRelationship < ActiveRecord::Base belongs_to :child, class_name: 'Enterprise' validates_presence_of :parent_id, :child_id - validates_uniqueness_of :child_id, scope: :parent_id + validates_uniqueness_of :child_id, scope: :parent_id, message: "^That relationship is already established." scope :with_enterprises, joins('LEFT JOIN enterprises AS parent_enterprises ON parent_enterprises.id = enterprise_relationships.parent_id').