diff options
-rw-r--r-- | vendor/plugins/custom_err_msg/MIT-LICENSE | 20 | ||||
-rw-r--r-- | vendor/plugins/custom_err_msg/README | 37 | ||||
-rw-r--r-- | vendor/plugins/custom_err_msg/init.rb | 1 | ||||
-rw-r--r-- | vendor/plugins/custom_err_msg/lib/custom_error_message.rb | 29 |
4 files changed, 87 insertions, 0 deletions
diff --git a/vendor/plugins/custom_err_msg/MIT-LICENSE b/vendor/plugins/custom_err_msg/MIT-LICENSE new file mode 100644 index 000000000..420110bde --- /dev/null +++ b/vendor/plugins/custom_err_msg/MIT-LICENSE @@ -0,0 +1,20 @@ +Copyright (c) 2006 David Easley
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\ No newline at end of file diff --git a/vendor/plugins/custom_err_msg/README b/vendor/plugins/custom_err_msg/README new file mode 100644 index 000000000..a0488dc7a --- /dev/null +++ b/vendor/plugins/custom_err_msg/README @@ -0,0 +1,37 @@ +Custom Error Message
+====================
+
+This plugin gives you the option to not have your custom validation error message
+prefixed with the attribute name. Ordinarily, if you have, say:
+
+ validates_acceptance_of :accepted_terms, :message => 'Please accept the terms of service'
+
+You'll get the following error message:
+
+ Accepted terms Please accept the terms of service
+
+This plugin allows you to omit the attribute name for specific messages. All you have to do
+is begin the message with a '^' character. Example:
+
+ validates_acceptance_of :accepted_terms, :message => '^Please accept the terms of service'
+
+
+Detail
+------
+
+Redefines 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.
+
+
+Download
+--------
+
+http://rubyforge.org/projects/custom-error-message/
+
+
+Bugs & feedback
+---------------
+
+Please send bug reports, patches and feedback to David Easley at easleydp@gmail.com
diff --git a/vendor/plugins/custom_err_msg/init.rb b/vendor/plugins/custom_err_msg/init.rb new file mode 100644 index 000000000..bec6c3021 --- /dev/null +++ b/vendor/plugins/custom_err_msg/init.rb @@ -0,0 +1 @@ +require 'custom_error_message'
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
|