Warum ist eine Aktualisierung attachment_fu jede Befestigung statt nur die geänderten welche?

StackOverflow https://stackoverflow.com/questions/1363160

Frage

Ich habe ein Objektmodell mit einem has_many und accepts_nested_attributes_for auf einem Bildmodell, das attachment_fu verwendet. Aktualisieren einer Immobilie die folgenden Code Ergebnisse in einer Datenbank UPDATE für jedes einzelne Bild mit (und jedes Bild Thumbnail), egal ob es Veränderungen waren oder nicht.

properties_controller.rb

  def update
    @property.update_attributes params[:property]
    redirect_to edit_property_path(@property)
  end

_form.html.erb

<% form_for @property do |property| %>  
  ...
  <ul id='image-admin'>
    <% @property.images.each do |image| %>
      <li>
      <%= image_tag image.public_filename(:front), :alt=> h(image.caption), :size => "218x160" %>
      <% property.fields_for :images, image do |img| %>
        <%= img.hidden_field :ordering, :class => 'order' %>
        <%= img.text_field :caption %>
        <span class='img_remove'>
          Remove ? <%= img.check_box '_delete' %>
        </span>
      <% end %>
      </li>
    <% end %>
  </ul>
  ...
<% end %>

script / Server-Ausgabe

  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

Irgendwelche Ideen, warum (und wie ich aufhören kann) attachment_fu von diesem? Es sieht aus wie denkt er, dass die Größe Attribut geändert hat, aber ich kann keinen Grund sehen (in meinem Code oder in attachment_fu), warum es sollte daran denken.

War es hilfreich?

Lösung 2

Nun, ich sollte gesucht etwas gründlicher Stackoverflow haben, bevor dieses Posting, wie Matchu hat gegabelt attachment_fu und hat dieses Problem gelöst über in Frage href="https://stackoverflow.com/questions/913555/attachmentfu-dont-reload-thumbnails">. Ersetzen technoweenie ist ein mit diesem gelöst hat alle meine Probleme.

Andere Tipps

fields_for wiederholt die geschlossenen Felder für jedes Bild in dem Verein. Aber Sie haben eine äußere Schleife, die fields_for für jedes Bild in der Vereinigung wiederholt. Als Ergebnis, wenn Sie einreichen Sie viel mehr Updates sind zu senden, als Sie werden möchten, senden.

Versuchen Sie diese:

<% form_for @property do |property| %>  
  ...
  <ul id='image-admin'>
    <% property.fields_for :images, image do |img| %>
      <li>
      <%= image_tag img.object.public_filename(:front), :alt=> h(img.object.caption), :size => "218x160" %>
        <%= img.hidden_field :ordering, :class => 'order' %>
        <%= img.text_field :caption %>
        <span class='img_remove'>
          Remove ? <%= img.check_box '_delete' %>
        </span>
      </li>
    <% end %>
  </ul>
  ...
<% end %>
scroll top