Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy is attachment_fu updating every attachment instead of just the changed ones?
    text
    copied!<p>I have a Property model with a <code>has_many</code> and <code>accepts_nested_attributes_for</code> on a Image model which uses <code>attachment_fu</code>. Updating a Property using the following code results in a database UPDATE for every single image (and each image thumbnail) no matter whether there were changes to it or not.</p> <p>properties_controller.rb</p> <pre><code> def update @property.update_attributes params[:property] redirect_to edit_property_path(@property) end </code></pre> <p>_form.html.erb</p> <pre><code>&lt;% form_for @property do |property| %&gt; ... &lt;ul id='image-admin'&gt; &lt;% @property.images.each do |image| %&gt; &lt;li&gt; &lt;%= image_tag image.public_filename(:front), :alt=&gt; h(image.caption), :size =&gt; "218x160" %&gt; &lt;% property.fields_for :images, image do |img| %&gt; &lt;%= img.hidden_field :ordering, :class =&gt; 'order' %&gt; &lt;%= img.text_field :caption %&gt; &lt;span class='img_remove'&gt; Remove ? &lt;%= img.check_box '_delete' %&gt; &lt;/span&gt; &lt;% end %&gt; &lt;/li&gt; &lt;% end %&gt; &lt;/ul&gt; ... &lt;% end %&gt; </code></pre> <p>script/server output</p> <pre><code> SQL (8.7ms) COMMIT SQL (0.1ms) BEGIN Image Update (0.3ms) UPDATE `images` SET `updated_at` = '2009-09-01 15:17:19', `size` = 103402 WHERE `id` = 350 Image Load (0.5ms) SELECT * FROM `images` WHERE (`images`.`thumbnail` = 'small' AND `images`.`parent_id` = 350) ORDER BY ordering ASC LIMIT 1 Image Update (0.3ms) UPDATE `images` SET `updated_at` = '2009-09-01 15:17:19', `size` = 60535 WHERE `id` = 352 Image Load (0.5ms) SELECT * FROM `images` WHERE (`images`.`thumbnail` = 'front' AND `images`.`parent_id` = 350) ORDER BY ordering ASC LIMIT 1 Image Update (0.3ms) UPDATE `images` SET `updated_at` = '2009-09-01 15:17:19', `size` = 39888 WHERE `id` = 353 Image Load (0.4ms) SELECT * FROM `images` WHERE (`images`.`thumbnail` = 'thumb' AND `images`.`parent_id` = 350) ORDER BY ordering ASC LIMIT 1 Image Update (0.3ms) UPDATE `images` SET `updated_at` = '2009-09-01 15:17:19', `size` = 3510 WHERE `id` = 351 SQL (0.9ms) COMMIT SQL (0.1ms) BEGIN Image Update (0.3ms) UPDATE `images` SET `updated_at` = '2009-09-01 15:17:19', `size` = 100387 WHERE `id` = 338 Image Load (0.4ms) SELECT * FROM `images` WHERE (`images`.`thumbnail` = 'small' AND `images`.`parent_id` = 338) ORDER BY ordering ASC LIMIT 1 Image Update (0.3ms) UPDATE `images` SET `updated_at` = '2009-09-01 15:17:19', `size` = 58212 WHERE `id` = 340 Image Load (0.4ms) SELECT * FROM `images` WHERE (`images`.`thumbnail` = 'front' AND `images`.`parent_id` = 338) ORDER BY ordering ASC LIMIT 1 Image Update (0.8ms) UPDATE `images` SET `updated_at` = '2009-09-01 15:17:20', `size` = 38101 WHERE `id` = 341 Image Load (0.4ms) SELECT * FROM `images` WHERE (`images`.`thumbnail` = 'thumb' AND `images`.`parent_id` = 338) ORDER BY ordering ASC LIMIT 1 Image Update (0.3ms) UPDATE `images` SET `updated_at` = '2009-09-01 15:17:20', `size` = 3241 WHERE `id` = 339 SQL (0.8ms) COMMIT </code></pre> <p>Any ideas why (and how I can stop) <code>attachment_fu</code> from doing this ? It looks like it thinks that the size attribute has changed but I can't see any reason (in my code, or in <code>attachment_fu</code>) why it should think that.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload