# Attachment\_fu DEPRECATION WARNING: ActiveRecord::Errors.defa

**URL:** <https://www.ruby-forum.com/t/attachment-fu-deprecation-warning-activerecord-errors-defa/186182>\
**Category:** Rails\
**Created:** [April 1, 2010, 7:06pm UTC](https://www.ruby-forum.com/t/attachment-fu-deprecation-warning-activerecord-errors-defa/186182 "2010-04-01T19:06:58Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![simonr](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/6f9a4e/32.png) [@simonr](https://www.ruby-forum.com/u/simonr)\
**Post date:** [April 1, 2010, 7:06pm UTC](https://www.ruby-forum.com/t/attachment-fu-deprecation-warning-activerecord-errors-defa/186182/1 "2010-04-01T19:06:58Z")

</div>

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
