# attachment\_fu

**URL:** <https://discuss.rubyonrails.org/t/attachment-fu/24628>\
**Category:** rubyonrails-talk\
**Created:** [February 9, 2008, 2:07pm UTC](https://discuss.rubyonrails.org/t/attachment-fu/24628 "2008-02-09T14:07:00Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![11175](https://avatars.discourse-cdn.com/v4/letter/1/8edcca/32.png) [@11175](https://discuss.rubyonrails.org/u/11175)\
**Post date:** [February 9, 2008, 2:07pm UTC](https://discuss.rubyonrails.org/t/attachment-fu/24628/1 "2008-02-09T14:07:00Z")

</div>

Hello, &nbsp;&nbsp;I am using attachment\_fu to handle my images. i get an error message "cant convert nil into string" when updating a person if i do not specify the image for the person. Does anyone know whats wrong.

---

<div class="post-metadata">

**Author:** ![AndyV1](https://avatars.discourse-cdn.com/v4/letter/a/5fc32e/32.png) [@AndyV1](https://discuss.rubyonrails.org/u/AndyV1)\
**Post date:** [February 10, 2008, 8:56pm UTC](https://discuss.rubyonrails.org/t/attachment-fu/24628/2 "2008-02-10T20:56:48Z")

</div>

Just stating the obvious: if you don't supply a file then attachment\_fu chokes on the uploaded\_data being nil.

From a broader perspective it sounds like you may have included the images as part of the Person model. You're better off restructuring the images into their own model. If only Person will have images then use a has\_one/has\_many and belongs\_to relationship to associate them. If you'll have several models that need images then use a polymorphic association (Photo belongs\_to :photographable, :polymorphic=\>true and Person has\_many :photos, :as=\>:photographable). By doing that you can test for the presence of an uploaded image and only create the Photo model if one was supplied.

One word of warning -- avoid naming the model Image. Long story short, the RESTful image\_path causes some issues by aliasing a controller method.

HTH, AndyV

---

<div class="post-metadata">

**Author:** ![11175](https://avatars.discourse-cdn.com/v4/letter/1/8edcca/32.png) [@11175](https://discuss.rubyonrails.org/u/11175)\
**Post date:** [February 12, 2008, 3:55pm UTC](https://discuss.rubyonrails.org/t/attachment-fu/24628/3 "2008-02-12T15:55:26Z")

</div>

AndyV wrote:

> Just stating the obvious: if you don't supply a file then attachment\_fu chokes on the uploaded\_data being nil.
> 
> From a broader perspective it sounds like you may have included the images as part of the Person model. You're better off restructuring the images into their own model. If only Person will have images then use a has\_one/has\_many and belongs\_to relationship to associate them. If you'll have several models that need images then use a polymorphic association (Photo belongs\_to :photographable, :polymorphic=\>true and Person has\_many :photos, :as=\>:photographable). By doing that you can test for the presence of an uploaded image and only create the Photo model if one was supplied.
> 
> One word of warning -- avoid naming the model Image. Long story short, the RESTful image\_path causes some issues by aliasing a controller method.
> 
> HTH, AndyV

Hello, &nbsp;&nbsp;Thanks for the information I will try that out. I need photos for multiple models. Can you please explain me or give me some link to understand the polymorphic association. Is it correc that I will need to have a photographable\_id in the photo table.

Thank you.
