Skip to content

Commit

Permalink
ActiveResource::Errors support added
Browse files Browse the repository at this point in the history
Signed-off-by: Victor Gumayunov <gumayunov@gmail.com>
  • Loading branch information
gtd authored and Victor Gumayunov committed Feb 7, 2009
1 parent d9671a6 commit c000ef1
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
1 change: 1 addition & 0 deletions MIT-LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
Some contributions:
Victor Gumayunov
Daniel Cadenas
Gabe da Silveira

Initial coded by:
Copyright (c) 2006 David Easley
Expand Down
3 changes: 3 additions & 0 deletions init.rb
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
require 'custom_error_message'

ActiveRecord::Errors.send(:include, CustomErrorMessage)
ActiveResource::Errors.send(:include, CustomErrorMessage)
14 changes: 10 additions & 4 deletions lib/custom_error_message.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
module ActiveRecord
class Errors
module CustomErrorMessage
def self.included(receiver)
receiver.send :include, InstanceMethods
receiver.class_eval do
alias_method_chain :full_messages, :tilde
end
end

# Redefine the ActiveRecord::Errors::full_messages method:
module InstanceMethods
# Redefine the 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'

private
def full_messages_with_tilde
process_procs
Expand All @@ -18,7 +25,6 @@ def full_messages_with_tilde
end
end
end
alias_method_chain :full_messages, :tilde

def process_procs
@errors.each_pair do |field, messages|
Expand Down

0 comments on commit c000ef1

Please sign in to comment.