Attribute_fu and Paperclip

Hi

I'm using attribute_fu and paperclip to add multiple images to a
specific record.

This is working great when creating a new record but when I want to add
new images to an existing record through a common scaffold update, the
images upload but replace the existing images.

Any thoughts or advice?

Thank's

Do you have a separate model to hold the additional images? Or do you have N number of image "slots" per record? Paperclip manages each image as a virtual attribute of your model, and if you upload a new image in the same slot, that image will overwrite the previous one. Unless you're adding

has_attached_image :image1
has_attached_image :image2
...

and all the paperclip-specific fields that go with them, you are probably ending up with a single field to hold your images.

I'm not familiar with attribute_fu -- does that somehow work around this problem?

Walter

Walter Davis wrote in post #955464:

Hi

I'm using attribute_fu and paperclip to add multiple images to a
specific record.

This is working great when creating a new record but when I want to
add
new images to an existing record through a common scaffold update, the
images upload but replace the existing images.

Do you have a separate model to hold the additional images? Or do you
have N number of image "slots" per record? Paperclip manages each
image as a virtual attribute of your model, and if you upload a new
image in the same slot, that image will overwrite the previous one.
Unless you're adding

has_attached_image :image1
has_attached_image :image2
...

and all the paperclip-specific fields that go with them, you are
probably ending up with a single field to hold your images.

I'm not familiar with attribute_fu -- does that somehow work around
this problem?

Walter

Hi Walter,

I follow this tuto :
http://www.mfischer.com/wordpress/2009/02/02/multiple-image-upload-and-crop-with-rails/

without the cropping part.

Also, this problem came when i upgrade my app to 2.3.5 because before it
was working find…

I don't find the solution…

Oh, ok. You are ending up with something that is now native to Rails. Attribute_fu seems to be doing what accepts_nested_attributes_for does now. I suspect you can refactor your application to remove that plug-in and move ahead.

Nested forms came into being somewhere in the 2.3 timeframe, so you might want to find a different tutorial that is more up to date. There's an excellent Railscast about them.

You are in fact doing what I thought you needed to -- you have a separate model for your images, and so you can have N number of them related to a single parent model.

Walter

Hi Walter,

I'd found the problem.

my model upload has article_id, description, photo_filenane

In my partial: _upload.rhtml

if i just put:

<div class="upload">

  <%= f.file_field :photo %>
<%= f.remove_link "remove" %>

</div>

when i update, it delete my photos.

but if i put:

<div class="upload">

<%= f.text_field :description %>

  <%= f.file_field :photo %>
<%= f.remove_link "remove" %>

</div>

it works fine…

Strange…

Anyway, thanks!