# Attachment\_fu validation error

**URL:** <https://www.ruby-forum.com/t/attachment-fu-validation-error/108182>\
**Category:** Rails\
**Created:** [June 29, 2007, 8:35pm UTC](https://www.ruby-forum.com/t/attachment-fu-validation-error/108182 "2007-06-29T20:35:04Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![fxn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/77aa72/32.png) [@fxn](https://www.ruby-forum.com/u/fxn)\
**Post date:** [June 29, 2007, 8:35pm UTC](https://www.ruby-forum.com/t/attachment-fu-validation-error/108182/1 "2007-06-29T20:35:04Z")

</div>

I have this class:

class Logo \< ActiveRecord::Base  
has\_one :something

```
 has_attachment :content_type => :image,
                :storage => :db_file,
                :max_size => 500.kilobytes
                :thumbnails => {:web => '150x100', :pdf =>

```

‘150x100’},  
:processor =\> ‘MiniMagick’

```
 validates_as_attachment

```

end

OK, logos are working great in the application, resizing, storage,  
retrieval, …, fine. But the validation of existing logos fails with  
(complete trace below)

Logo.find(:first).valid?  
NameError: undefined local variable or method `full\_filename’ for  
#Logo:0x3561ed8

And unfortunately that is triggered by something’s  
validates\_associated if no logo is uploaded in its edition. I don’t  
see why valid? ends up calling set\_size\_from\_temp\_path, sizes were  
correctly computed and stored on creation:

pp Logo.find(:first)  
#\<Logo:0x35593f0  
@attributes=  
{“content\_type”=\>“image/jpeg”,  
“size”=\>“187697”,  
“thumbnail”=\>nil,  
“id”=\>“1”,  
“height”=\>“768”,  
“db\_file\_id”=\>“3”,  
“filename”=\>“img\_1651.jpeg”,  
“parent\_id”=\>nil,  
“width”=\>“1024”}\>

This happens with all logos in the application, isn’t that  
suspicious? I’ve not diffed svn with the installed version but both  
CHANGELOGs start with

- April 2, 2007 \*

– fxn

Logo.find(:first).valid?  
NameError: undefined local variable or method `full_filename' for #<Logo:0x3561ed8> from ./script/../config/../config/../vendor/rails/ activerecord/lib/active_record/base.rb:1860:in`method\_missing’  
from ./script/…/config/…/config/…/vendor/plugins/  
attachment\_fu/lib/technoweenie/attachment\_fu.rb:276:in `temp_paths' from ./script/../config/../config/../vendor/plugins/ attachment_fu/lib/technoweenie/attachment_fu.rb:270:in`temp\_path’  
from ./script/…/config/…/config/…/vendor/plugins/  
attachment\_fu/lib/technoweenie/attachment\_fu.rb:236:in  
`save_attachment?' from ./script/../config/../config/../vendor/plugins/ attachment_fu/lib/technoweenie/attachment_fu.rb:339:in`set\_size\_from\_temp\_path’  
from ./script/…/config/…/config/…/vendor/rails/  
activerecord/lib/active\_record/callbacks.rb:333:in `send' from ./script/../config/../config/../vendor/rails/ activerecord/lib/active_record/callbacks.rb:333:in`callback’  
from ./script/…/config/…/config/…/vendor/rails/  
activerecord/lib/active\_record/callbacks.rb:330:in `each' from ./script/../config/../config/../vendor/rails/ activerecord/lib/active_record/callbacks.rb:330:in`callback’  
from ./script/…/config/…/config/…/vendor/rails/  
activerecord/lib/active\_record/callbacks.rb:295:in `valid?’  
from (irb):16

---

<div class="post-metadata">

**Author:** ![fxn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/77aa72/32.png) [@fxn](https://www.ruby-forum.com/u/fxn)\
**Post date:** [June 29, 2007, 10:38pm UTC](https://www.ruby-forum.com/t/attachment-fu-validation-error/108182/2 "2007-06-29T22:38:22Z")

</div>

On Jun 29, 2007, at 8:33 PM, Xavier N. wrote:

> validates\_associated if no logo is uploaded in its edition. I don’t  
> see why valid? ends up calling set\_size\_from\_temp\_path, sizes were  
> correctly computed and stored on creation:

I’ve seen something: that method is set as a before\_validation,  
that’s why it gets called. Following the traces the plugin tries to  
determine whether the logo needs to be saved in save\_attachment?  
which in the end results in a call to temp\_paths

def temp\_paths  
@temp\_paths ||= (new\_record? || !File.exist?(full\_filename)) ?  
[] : [copy\_to\_temp\_file(full\_filename)]  
end

full\_filename is implemented by the file system and s3 backends, but  
it is missing in the database backend which is the one I am using. I  
don’t know enough about the plugin at this moment to propose a  
suitable fix, but at least I write a custom quick fix and go on with  
the project.

– fxn
