From 6e67b49ff8584da5ae58fa7cf75d62b1cc328091 Mon Sep 17 00:00:00 2001 From: Dustin Anderson Date: Fri, 13 Feb 2009 04:43:45 +0800 Subject: [PATCH] One tweak to support Rails 2.2 I18n validation error message (due to deprecated ActiveRecord::Errors.default_error_messages) - Tests were getting very ugly with all the deprec warning messages Signed-off-by: rick --- lib/technoweenie/attachment_fu.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/technoweenie/attachment_fu.rb b/lib/technoweenie/attachment_fu.rb index a041c61..d5e261b 100644 --- a/lib/technoweenie/attachment_fu.rb +++ b/lib/technoweenie/attachment_fu.rb @@ -422,7 +422,11 @@ module Technoweenie # :nodoc: def attachment_attributes_valid? [:size, :content_type].each do |attr_name| enum = attachment_options[attr_name] - errors.add attr_name, ActiveRecord::Errors.default_error_messages[:inclusion] unless enum.nil? || enum.include?(send(attr_name)) + if Object.const_defined?(:I18n) # Rails >= 2.2 + I18n.translate("activerecord.errors.messages.inclusion", attr_name => enum) + else + errors.add attr_name, ActiveRecord::Errors.default_error_messages[:inclusion] unless enum.nil? || enum.include?(send(attr_name)) + end end end