Attachment_fu DEPRECATION WARNING: ActiveRecord::Errors.defa

I’m using the attachment_fu plugin to upload large files. I’m using the
latest version and I’m running it under Rails 2.3.5.

My file upload doesn’t work and I get this error in the log:

DEPRECATION WARNING: ActiveRecord::Errors.default_error_messages has
been deprecated. Please use
I18n.translate(‘activerecord.errors.messages’)… (called from
default_error_messages at
C:/ruby/1.8.6/lib/ruby/gems/1.8/gems/activerecord-2.3.4/lib/active_record/validations.rb:131)

At first I guessed that there was an error in my code, and the system is
trying to display an error message, but failing. In fact, it turns out
that there’s nothing wrong with my code!

To fix the problem I edited
vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu.rb around
line 385. The original code was:

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))
end
end

I changed it to:

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))
# This is an internationalised version of “size is not
included in the list” etc
inclusion_error_message =
I18n.translate"activerecord.errors.messages.too_short"
errors.add attr_name, inclusion_error_message unless
enum.nil? ||
enum.include?(send(attr_name))
end
end

And now my upload works.

If the locale speaks English, then
ActiveRecord::Errors.default_error_messages[:inclusion]
becomes
“is not included in the list”

The code seems to be building a list of error messages “size is not
included in the list”, “content type is not included in the list” and so
on. It will use them if any of those fields are missing. (In my case,
they were all present, so the messages are not needed.

However, it’s using a deprecated method to build the list, and the
result is a fatal error. I think my replacement code does the same
thing, but using the modern style.

Interesting use of the term “deprecated” by the way. In other systems,
it means “you can use this feature but in a future version it won’t
work.” Here it seems to mean “Ha ha! I’m going to waste hours of your
time by throwing a fatal error for no good reason.”

Simon