diff options
author | francis <francis> | 2007-11-07 08:29:30 +0000 |
---|---|---|
committer | francis <francis> | 2007-11-07 08:29:30 +0000 |
commit | 3c1a4bae631663f7660f947c59d898f076f6e0b8 (patch) | |
tree | 7cac21487787019f112c5801c59d0b9e7a5fd69e /vendor/plugins/custom_err_msg/lib | |
parent | 2e68d48c175a218ea819f0ef4c7e8c5a1baf02cf (diff) |
Original version of custom error messgae plugin
Diffstat (limited to 'vendor/plugins/custom_err_msg/lib')
-rw-r--r-- | vendor/plugins/custom_err_msg/lib/custom_error_message.rb | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/vendor/plugins/custom_err_msg/lib/custom_error_message.rb b/vendor/plugins/custom_err_msg/lib/custom_error_message.rb new file mode 100644 index 000000000..4dcc459c9 --- /dev/null +++ b/vendor/plugins/custom_err_msg/lib/custom_error_message.rb @@ -0,0 +1,29 @@ +module ActiveRecord
+ class Errors
+
+ # Redefine the ActiveRecord::Errors::full_messages method:
+ # Returns all the full error messages in an array. 'Base' messages are handled as usual.
+ # Non-base messages are prefixed with the attribute name as usual UNLESS they begin with '^'
+ # in which case the attribute name is omitted.
+ # E.g. validates_acceptance_of :accepted_terms, :message => '^Please accept the terms of service'
+ def full_messages
+ full_messages = []
+
+ @errors.each_key do |attr|
+ @errors[attr].each do |msg|
+ next if msg.nil?
+
+ if attr == "base"
+ full_messages << msg
+ elsif msg =~ /^\^/
+ full_messages << msg[1..-1]
+ else
+ full_messages << @base.class.human_attribute_name(attr) + " " + msg
+ end
+ end
+ end
+
+ return full_messages
+ end
+ end
+end
|