# Attachment\_fu problems on updates

**URL:** <https://www.ruby-forum.com/t/attachment-fu-problems-on-updates/123090>\
**Category:** Rails\
**Created:** [December 13, 2007, 10:56pm UTC](https://www.ruby-forum.com/t/attachment-fu-problems-on-updates/123090 "2007-12-13T22:56:13Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![chrisolsen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c6cbf5/32.png) [@chrisolsen](https://www.ruby-forum.com/u/chrisolsen)\
**Post date:** [December 13, 2007, 10:56pm UTC](https://www.ruby-forum.com/t/attachment-fu-problems-on-updates/123090/1 "2007-12-13T22:56:13Z")

</div>

On the creation of a member the member’s picture uploads as it should.  
However, when updating the member, while selecting a new picture, an  
error is thrown:

can’t convert nil into String  
RAILS\_ROOT: /Users/chris/Documents/Projects/Rails/CommunityCMS/trunk

Application Trace | Framework Trace | Full Trace  
vendor/plugins/attachment\_fu/lib/technoweenie/attachment\_fu/backends/file\_system\_backend.rb:21:in  
`join' vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu/backends/file_system_backend.rb:21:in`full\_filename’  
vendor/plugins/attachment\_fu/lib/technoweenie/attachment\_fu.rb:281:in  
`temp_paths' vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu.rb:275:in`temp\_path’  
vendor/plugins/attachment\_fu/lib/technoweenie/attachment\_fu.rb:241:in  
`save_attachment?' vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu.rb:344:in`set\_size\_from\_temp\_path’  
vendor/rails/activerecord/lib/active\_record/callbacks.rb:307:in `send’

If I update the user without selecting a new picture, the users picture  
is lost (the db row values are set to nil)

## Here is the controller code for the update:

def update  
@member = Member.find(params[:id])  
#try to not set the photo if a new one is not uploaded  
@photo = @member.build\_photo(params[:photo]) unless  
params[:photo].nil?

```
respond_to do |format|
  if @member.update_attributes(params[:member])
      ....
end

```

end

## Here is the Member model code:

class Member \< ActiveRecord::Base  
validates\_presence\_of :first\_name, :last\_name, :city, :region,  
:region\_code  
has\_many :groups, :through =\> :group\_members  
has\_one :photo, :as =\> “photo\_for”

validates\_associated :photo

end

## Here is the file\_system\_backend (where the error is occurring):

def full\_filename(thumbnail = nil)  
file\_system\_path = (thumbnail ? thumbnail\_class :  
self).attachment\_options[:path\_prefix].to\_s  
#here is the join that is failing  
#logger.info “rails root:” + RAILS\_ROOT =\> /Users/…  
#logger.info “file sys path” + file\_system\_path =\> public/photos  
#logger.info thumbnail =\> nothing show up here  
File.join(RAILS\_ROOT, file\_system\_path,  
\*partitioned\_path(thumbnail\_name\_for(thumbnail)))  
end

The photo model is polymorphic which is why it exists as a separate  
model.

I have never had this problem before, but this is the first polymorphic  
relation that I have used to link to the uploaded images.

Thanks for the help.

---

<div class="post-metadata">

**Author:** ![chrisolsen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c6cbf5/32.png) [@chrisolsen](https://www.ruby-forum.com/u/chrisolsen)\
**Post date:** [December 31, 2007, 6:24am UTC](https://www.ruby-forum.com/t/attachment-fu-problems-on-updates/123090/2 "2007-12-31T06:24:08Z")

</div>

Some of the issues above have been fixed, but I am still having problems  
uploading a photo when editing a member that was created without a  
photo.

It is failing in the exact same spot.

Thanks for the help.

=============================  
TypeError in Admin/membersController#update

can’t convert nil into String  
RAILS\_ROOT: /Users/chris/Documents/Projects/Rails/CommunityCMS/trunk

Application Trace | Framework Trace | Full Trace  
vendor/plugins/attachment\_fu/lib/technoweenie/attachment\_fu/backends/file\_system\_backend.rb:21:in  
`join' vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu/backends/file_system_backend.rb:21:in`full\_filename’  
vendor/plugins/attachment\_fu/lib/technoweenie/attachment\_fu.rb:281:in  
`temp_paths' vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu.rb:275:in`temp\_path’  
vendor/plugins/attachment\_fu/lib/technoweenie/attachment\_fu.rb:241:in  
`save_attachment?' vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu.rb:344:in`set\_size\_from\_temp\_path’  
/Library/Ruby/Gems/1.8/gems/activerecord-2.0.2/lib/active\_record/callbacks.rb:307:in  
`send' /Library/Ruby/Gems/1.8/gems/activerecord-2.0.2/lib/active_record/callbacks.rb:307:in`callback’  
/Library/Ruby/Gems/1.8/gems/activerecord-2.0.2/lib/active\_record/callbacks.rb:304:in  
`each' /Library/Ruby/Gems/1.8/gems/activerecord-2.0.2/lib/active_record/callbacks.rb:304:in`callback’  
/Library/Ruby/Gems/1.8/gems/activerecord-2.0.2/lib/active\_record/callbacks.rb:269:in  
`valid?' /Library/Ruby/Gems/1.8/gems/activerecord-2.0.2/lib/active_record/validations.rb:933:in`save\_without\_transactions’  
/Library/Ruby/Gems/1.8/gems/activerecord-2.0.2/lib/active\_record/transactions.rb:108:in  
`save' /Library/Ruby/Gems/1.8/gems/activerecord-2.0.2/lib/active_record/connection_adapters/abstract/database_statements.rb:66:in`transaction’  
/Library/Ruby/Gems/1.8/gems/activerecord-2.0.2/lib/active\_record/transactions.rb:80:in  
`transaction' /Library/Ruby/Gems/1.8/gems/activerecord-2.0.2/lib/active_record/transactions.rb:100:in`transaction’  
/Library/Ruby/Gems/1.8/gems/activerecord-2.0.2/lib/active\_record/transactions.rb:108:in  
`save' /Library/Ruby/Gems/1.8/gems/activerecord-2.0.2/lib/active_record/transactions.rb:120:in`rollback\_active\_record\_state!’  
/Library/Ruby/Gems/1.8/gems/activerecord-2.0.2/lib/active\_record/transactions.rb:108:in  
`save' /Library/Ruby/Gems/1.8/gems/activerecord-2.0.2/lib/active_record/associations/has_one_association.rb:30:in`replace’  
/Library/Ruby/Gems/1.8/gems/activerecord-2.0.2/lib/active\_record/associations/has\_one\_association.rb:86:in  
`new_record' /Library/Ruby/Gems/1.8/gems/activerecord-2.0.2/lib/active_record/associations/has_one_association.rb:18:in`build’  
/Library/Ruby/Gems/1.8/gems/activerecord-2.0.2/lib/active\_record/associations.rb:1114:in  
`send' /Library/Ruby/Gems/1.8/gems/activerecord-2.0.2/lib/active_record/associations.rb:1114:in`build\_photo’  
app/controllers/admin/members\_controller.rb:75:in `update’

---

<div class="post-metadata">

**Author:** ![chrisolsen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c6cbf5/32.png) [@chrisolsen](https://www.ruby-forum.com/u/chrisolsen)\
**Post date:** [January 23, 2008, 1:31am UTC](https://www.ruby-forum.com/t/attachment-fu-problems-on-updates/123090/3 "2008-01-23T01:31:07Z")

</div>

Hello, i having troubles when try replace existing file for new, get  
the same error… some one can help?

On 31 dez 2007, 03:24, Chris O. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![chrisolsen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c6cbf5/32.png) [@chrisolsen](https://www.ruby-forum.com/u/chrisolsen)\
**Post date:** [January 23, 2008, 2:02am UTC](https://www.ruby-forum.com/t/attachment-fu-problems-on-updates/123090/4 "2008-01-23T02:02:07Z")

</div>

Thanks Chris, i post my question and code in another post in this  
link,  
[http://groups.google.de/group/rubyonrails-talk/browse\_thread/thread/f2510dfd535ebaf0](http://groups.google.de/group/rubyonrails-talk/browse_thread/thread/f2510dfd535ebaf0)

On 22 jan, 22:46, Chris O. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![chrisolsen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c6cbf5/32.png) [@chrisolsen](https://www.ruby-forum.com/u/chrisolsen)\
**Post date:** [January 23, 2008, 1:46am UTC](https://www.ruby-forum.com/t/attachment-fu-problems-on-updates/123090/5 "2008-01-23T01:46:48Z")

</div>

Daniel L. wrote:

> Hello, i having troubles when try replace existing file for new, get  
> the same error… some one can help?
> 
> On 31 dez 2007, 03:24, Chris O. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

The problem for me was that I was missing the unless params[:photo].nil?  
condition in the create method, which messed up the data when trying to  
do the update.

If that doesn’t help you out at all, post some of your code so we can  
take a look at it.
