Created
October 9, 2009 12:25
-
-
Save skojin/205971 to your computer and use it in GitHub Desktop.
prefix validation message with ^ to display it without attribute name
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# prefix validation message with ^ to display it without attribute name | |
# original idea: http://speakmy.name/2009/01/custom-validation-errors-in-rails-and-activerecord/ | |
class ActiveRecord::Error | |
CUSTOM_PREFIX = '^' | |
def full_message_with_custom_prefix | |
if @message.is_a?(String) && @message.mb_chars[0..(CUSTOM_PREFIX.size-1)] == CUSTOM_PREFIX | |
@message.mb_chars[(CUSTOM_PREFIX.size)..-1] | |
else | |
full_message_without_custom_prefix | |
end | |
end | |
alias_method_chain :full_message, :custom_prefix | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment