attachment_fu

Hello,   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.

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

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,   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.