Commit 2a1c3797b76fbee7208710eba8b12318ed9d4d88

Authored by Larissa Reis
1 parent 93103d85

Fixes the hidden tag that overwrited product qualifiers

  An hidden tag is used to update qualifiers_list in products even when
  said qualifiers_list is empty, so it would behave accordingly with the
  way the qualifiers are added dinamically using javascript and ajax
  (that is, the list represents the content of a product's qualifiers,
  so an empty list means that whatever qualifiers that the product had
  before should be removed). But this tag was overwriting the qualifiers
  and certifiers added by the user, thus making rails believe that the
  qualifiers list was always empty.

  I've changed the hidden tag to have a default value 'nil' (which is
  actually a string, but it works; I couldn't find a way to put an
  actual nil value), and when the qualifiers list is updated the method
  inside the model ignores qualifiers whose id value are 'nil'.

(ActionItem2328)
app/models/product.rb
... ... @@ -155,7 +155,7 @@ class Product < ActiveRecord::Base
155 155 def qualifiers_list=(qualifiers)
156 156 self.product_qualifiers.destroy_all
157 157 qualifiers.each do |qualifier_id, certifier_id|
158   - self.product_qualifiers.create(:qualifier_id => qualifier_id, :certifier_id => certifier_id)
  158 + self.product_qualifiers.create(:qualifier_id => qualifier_id, :certifier_id => certifier_id) if qualifier_id != 'nil'
159 159 end
160 160 end
161 161  
... ...
app/views/manage_products/_edit_info.rhtml
... ... @@ -50,7 +50,7 @@
50 50 _('Add new qualifier'),
51 51 "new_qualifier_row('#product-qualifiers-list', '#{escape_javascript(select_qualifiers(@product))}')"
52 52 ) %>
53   - <%= hidden_field_tag "product[qualifiers_list]" %>
  53 + <%= hidden_field_tag "product[qualifiers_list][nil]" %>
54 54 <% end %>
55 55  
56 56 <%= hidden_field_tag 'info-bar-update-url', @product.price_composition_bar_display_url, :class => 'bar-update-url' %>
... ...